fix install stage in specfile
[myplc.git] / bin / db-config
index f22e7f2..af08a13 100755 (executable)
@@ -3,12 +3,12 @@
 # Bootstraps the PLC database with a default administrator account and
 # a default site, defines default slice attribute types, and
 # creates/updates default system slices.
+# scan ordered scripts in /etc/planetlab/db-config.d
 #
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
+# Thierry Parmentelat <thierry.parmentelat@inria.fr>
 #
-# $Id$
-# $URL$
 
 import os,sys
 from optparse import OptionParser
@@ -20,20 +20,21 @@ def GetSnippets(directory):
     if os.path.exists(directory):
         try:
             filenames = os.listdir(directory)
-        except OSError, e:
-            raise Exception"Error when opening %s (%s)" % \
-                  (os.path.join(dir, file), e)
+        except OSError as e:
+            raise Exception("Error when opening %s (%s)" % \
+                  (os.path.join(dir, file), e))
             
-    ignored = (".bak","~",".rpmsave",".rpmnew",".orig")
+    # ignore files that contain either ~ or .
+    ignore_tokens = ("~",".")
     numberedfiles = {}
     for filename in filenames:
-        shouldIgnore = False
-        for ignore in ignored:
-            if filename.endswith(ignore):
-                shouldIgnore = True
+        ignore = False
+        for token in ignore_tokens:
+            if filename.find(token)>=0:
+                ignore = True
                 break
 
-        if not shouldIgnore:
+        if not ignore:
             parts = filename.split('-')
             if len(parts)>=2:
                 name = '-'.join(parts)
@@ -43,15 +44,15 @@ def GetSnippets(directory):
                     entry.append(name)
                     numberedfiles[number]=entry
                 except ValueError:
-                    shouldIgnore = True
+                    ignore = True
             else:
-                shouldIgnore = True
+                ignore = True
 
-        if shouldIgnore:
-            print "db-config: ignoring %s snippet" % filename
+        if ignore:
+            print("db-config: ignored %s snippet" % filename)
 
     filenames = []
-    keys = numberedfiles.keys()
+    keys = list(numberedfiles.keys())
     keys.sort()
     for k in keys:
         for filename in numberedfiles[k]:
@@ -64,8 +65,7 @@ def main():
     variables = cfg.variables()
 
     usage="%prog [-- options] [steps]"
-    release_url = "$URL$"
-    parser = OptionParser(usage=usage, version="%prog " + release_url )
+    parser = OptionParser(usage=usage )
     parser.add_option("-l","--list",dest="list_steps",action="store_true",default=False,
                       help="Lists available steps")
     parser.add_option("-v","--verbose",dest="verbose",action="store_true",default=False,
@@ -74,9 +74,9 @@ def main():
     (options,steps) = parser.parse_args()
     
     # Load variables into dictionaries
-    for category_id, (category, variablelist) in variables.iteritems():
-        globals()[category_id] = dict(zip(variablelist.keys(),
-                                          [variable['value'] for variable in variablelist.values()]))
+    for category_id, (category, variablelist) in variables.items():
+        globals()[category_id] = dict(list(zip(list(variablelist.keys()),
+                                          [variable['value'] for variable in list(variablelist.values())])))
 
     directory="/etc/planetlab/db-config.d"
     snippets = GetSnippets(directory)
@@ -95,16 +95,16 @@ def main():
         
         if options.list_steps:
             if not options.verbose: 
-                print snippet
+                print(snippet)
             else: 
-                print "Found step %s/%s"%(directory,snippet)
+                print("Found step %s/%s"%(directory,snippet))
                 os.system("rpm -qf %s/%s"%(directory,snippet))
             continue
 
         fullpath = os.path.join(directory, snippet)
         if options.verbose:
-            print "Running step %s"%fullpath
-        execfile(fullpath)
+            print("Running step %s"%fullpath)
+        exec(compile(open(fullpath).read(), fullpath, 'exec'))
 
 if __name__ == '__main__':
     main()