2to3 on accessory scripts
[myplc.git] / bin / plc-config
index ca6dc00..46b36ff 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 #
 # Script for basic access to the PlanetLab Central (PLC) configuration
 # file store.
@@ -16,7 +16,7 @@ from plc_config import PLCConfiguration
 
 
 def usage():
-    print """
+    print("""
 Script to access the PLC configuration file store.
     
 Usage: %s [OPTION]... [FILES]
@@ -48,13 +48,13 @@ Usage: %s [OPTION]... [FILES]
 
         -h, --help      This message
         -s, --save      Save changes to first configuration file
-""".lstrip() % sys.argv[0]
+""".lstrip() % sys.argv[0])
     sys.exit(1)
 
 
 def deprecated (message):
-    print "%s: deprecated usage"%sys.argv[0]
-    print message
+    print("%s: deprecated usage"%sys.argv[0])
+    print(message)
     sys.exit(1)
 
 def main():
@@ -83,7 +83,7 @@ def main():
 
     try:
         (opts, argv) = getopt.gnu_getopt(sys.argv[1:], shortopts, longopts)
-    except Exception, err:
+    except Exception as err:
         sys.stderr.write("Error: " + str(err) + os.linesep)
         sys.exit(1)
 
@@ -124,7 +124,7 @@ def main():
         elif opt == '-s' or opt == "--save":
             if not optval:
                 usage()
-            print 'parsed save option',optval
+            print('parsed save option',optval)
             save = optval
         elif opt == '-h' or opt == "--help":
             usage()
@@ -139,18 +139,18 @@ def main():
             plc.load(file)
         except IOError:
             pass
-        except Exception, err:
+        except Exception as err:
             sys.stderr.write("Error: %s: %s" % (file, str(err)) + os.linesep)
             sys.exit(1)
 
     # --category, --variable, --value
-    if category.has_key('id') and variable.has_key('id'):
-        if variable.has_key('value'):
+    if 'id' in category and 'id' in variable:
+        if 'value' in variable:
             plc.set(category, variable)
         else:
             (category, variable) = plc.get(category['id'], variable['id'])
-            if variable.has_key('value'):
-                print variable['value']
+            if 'value' in variable:
+                print(variable['value'])
 
     # --shell, --php, --xml
     if output is not None:
@@ -162,9 +162,9 @@ def main():
         # so that plc.d/{api,postgres} can create configs/site.xml 
         dirname = os.path.dirname (save)
         if (not os.path.exists (dirname)):
-            os.makedirs(dirname,0755)
+            os.makedirs(dirname,0o755)
             if (not os.path.exists (dirname)):
-                print "Cannot create dir %s - exiting" % dirname
+                print("Cannot create dir %s - exiting" % dirname)
                 sys.exit(1)
         
         plc.save(save)