#157 Migrate python2 scripts to python3
Merged 3 years ago by kevin. Opened 3 years ago by darknao.
fedora-infra/ darknao/ansible python2to3  into  master

@@ -1,16 +1,15 @@ 

- #!/usr/bin/python2

+ #!/usr/bin/python

  #

  # very simple python script to parse out /proc/mdstat

  # and give results for nagios to monitor

  #

  

  import sys

- import string

  

  devices = []

  

  try:

-     mdstat = string.split(open('/proc/mdstat').read(), '\n')

+     mdstat = open('/proc/mdstat').read().split('\n')

  except IOError:

      # seems we have no software raid on this machines

      sys.exit(0)
@@ -19,12 +18,12 @@ 

  i = 0

  for line in mdstat:

      if line[0:2] == 'md':

-         device = string.split(line)[0]

+         device = line.split()[0]

          devices.append(device)

-         status = string.split(mdstat[i+1])[-1]

-         if string.count(status, "_"):

+         status = mdstat[i+1].split()[-1]

+         if status.count("_"):

              # see if we can figure out what's going on

-             err = string.split(mdstat[i+2])

+             err = mdstat[i+2].split()

              msg = "device=%s status=%s" % (device, status)

              if len(err) > 0:

                  msg = msg + " rebuild=%s" % err[0]
@@ -36,10 +35,9 @@ 

      i = i + 1

  

  if not error:

-     print "DEVICES %s OK" % " ".join(devices)

+     print("DEVICES %s OK" % " ".join(devices))

      sys.exit(0)

  

  else:

-     print error

+     print(error)

      sys.exit(2)

- 

file modified
+3 -3
@@ -12,7 +12,7 @@ 

  

  def date_cheat(datestr):

      dc = subprocess.Popen(['date', '-d', datestr, '+%Y/%m/%d'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]

-     dc = dc.strip()

+     dc = dc.strip().decode()

      return dc

      

  
@@ -95,9 +95,9 @@ 

     

  def main(args):

      opts,args = parse_args(args)

-     for pb in glob.glob(logpath + '/' + opts.playbook):

+     for pb in glob.glob(os.path.join(logpath,opts.playbook)):

          pb_name = os.path.basename(pb)

-         for pb_logdir in glob.glob(pb + '/' + opts.datestr):

+         for pb_logdir in glob.glob(os.path.join(pb, opts.datestr)):

              if opts.list_pb:

                  print(pb_name)

                  continue

First is check_raid, which should now work on python2 host as well as python3.
Next one on my list is scripts/logview.

1 new commit added

  • scripts/logview: Few fixups for python3 compatibility
3 years ago

If you need more scripts to port over python3, just let me know.

rebased onto 30d704f

3 years ago

Pull-Request has been merged by kevin

3 years ago