[Collab-qa-commits] r1119 - udd/src

neronus-guest at alioth.debian.org neronus-guest at alioth.debian.org
Tue Aug 19 09:41:50 UTC 2008


Author: neronus-guest
Date: 2008-08-19 09:41:49 +0000 (Tue, 19 Aug 2008)
New Revision: 1119

Removed:
   udd/src/udd-update.py
Modified:
   udd/src/udd-dispatch.py
Log:
Moved code from udd-update.py to udd-dispatch.py


Modified: udd/src/udd-dispatch.py
===================================================================
--- udd/src/udd-dispatch.py	2008-08-18 14:29:39 UTC (rev 1118)
+++ udd/src/udd-dispatch.py	2008-08-19 09:41:49 UTC (rev 1119)
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# Last-Modified: <Sun Aug 17 12:03:34 2008>
+# Last-Modified: <Tue Aug 19 09:38:06 2008>
 
 """Dispatch udd gatherers
 
@@ -20,48 +20,48 @@
     sys.exit(1)
 
   command = sys.argv[2]
-  if command not in ('run', 'setup', 'drop', 'tables'):
-    sys.stderr.write("command has to be one of 'run', 'setup', 'drop' and 'tables'\n")
+  if command not in ('run', 'setup', 'drop', 'tables', 'update'):
+    sys.stderr.write("command has to be one of 'run', 'setup', 'drop', 'update' and 'tables'\n")
     sys.exit(1)
 
-  # Check the configuration
   config = udd.aux.load_config(open(sys.argv[1]).read())
 
   types = config['general']['types']
 
-  for src in sys.argv[3:]:
-    if not src in config:
-      raise udd.aux.ConfigException("%s is not specified in %s" % (src, sys.argv[1]))
-
   connection = udd.aux.open_connection(config)
 
   # Process the sources
   for src in sys.argv[3:]:
     src_config = config[src]
     type = src_config['type']
-    if not type in types:
-      print "No script specified for type " + src['type']
-      sys.exit(1)
-
-
-    (src_command,rest) = types[type].split(None, 1)
-    
     udd.aux.lock(config, src)
     try:
-      if src_command == "exec":
-	system(rest + " " + sys.argv[1] + " " + sys.argv[2] + " " + src)
-      elif src_command == "module":
-	exec("import " + rest)
-	exec "gatherer = " + rest + ".get_gatherer(connection, config, src)"
-	if command == 'tables':
-	  exec "tables = gatherer.%s()" % command
-	  print "\n".join(tables)
-	else:
-	  exec "gatherer.%s()" % command
-      if 'timestamp-folder' in config['general']:
-	f = open(os.path.join(config['general']['timestamp-folder'], src+".dispatch"), "w")
-	f.write(asctime())
-	f.close()
+      # If the command is update, we need a special case. Otherwise we can just use the gatherer's methods
+      if command == 'update':
+	if "update-command" in src_config:
+	  result = system(src_config['update-command']) 
+	  if result != 0:
+	    sys.exit(result)
+	  if 'timestamp-folder' in config['general']:
+	    f = open(os.path.join(config['general']['timestamp-folder'], src+".update"), "w")
+	    f.write(asctime())
+	    f.close()
+      else:
+	(src_command,rest) = types[type].split(None, 1)
+	if src_command == "exec":
+	  system(rest + " " + sys.argv[1] + " " + sys.argv[2] + " " + src)
+	elif src_command == "module":
+	  exec("import " + rest)
+	  exec "gatherer = " + rest + ".get_gatherer(connection, config, src)"
+	  if command == 'tables':
+	    exec "tables = gatherer.%s()" % command
+	    print "\n".join(tables)
+	  else:
+	    exec "gatherer.%s()" % command
+	if 'timestamp-folder' in config['general']:
+	  f = open(os.path.join(config['general']['timestamp-folder'], src+".dispatch"), "w")
+	  f.write(asctime())
+	  f.close()
     except:
       udd.aux.unlock(config, src)
       raise

Deleted: udd/src/udd-update.py
===================================================================
--- udd/src/udd-update.py	2008-08-18 14:29:39 UTC (rev 1118)
+++ udd/src/udd-update.py	2008-08-19 09:41:49 UTC (rev 1119)
@@ -1,43 +0,0 @@
-#!/usr/bin/env python
-# Last-Modified: <Tue Aug 12 16:19:09 2008>
-
-"""
-This script executes the update statements for selected sources
-"""
-
-import sys
-from os import system
-from time import asctime
-import os.path
-import udd.aux
-
-def print_help():
-  print 'Usage: ' + sys.argv[0] + " <configuration> <source1> [source2 source3 ...]"
-
-if __name__ == '__main__':
-  if len(sys.argv) < 3:
-    print_help()
-    sys.exit(1)
-
-  config = udd.aux.load_config(open(sys.argv[1]).read())
-
-  for src in sys.argv[2:]:
-    if not src in config:
-      raise udd.aux.ConfigException("%s is not specified in %s" % (src, sys.argv[1]))
-
-  for src in sys.argv[2:]:
-    src_cfg = config[src]
-    if "update-command" in src_cfg:
-      udd.aux.lock(config, src)
-      try:
-	result = system(src_cfg['update-command']) 
-	if result != 0:
-	  sys.exit(result)
-	if 'timestamp-folder' in config['general']:
-	  f = open(os.path.join(config['general']['timestamp-folder'], src+".update"), "w")
-	  f.write(asctime())
-	  f.close()
-      except:
-	udd.aux.unlock(config, src)
-	raise
-




More information about the Collab-qa-commits mailing list