changeset 545:24dfe316e79a

(James) fixed issues when running locally and rsync command
author desjagui@atchoum.iro.umontreal.ca
date Tue, 18 Nov 2008 19:31:56 -0500
parents 5b4ccbf022c8
children cb8eabe7d941
files pylearn/dbdict/dbdict_run_sql.py
diffstat 1 files changed, 25 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/pylearn/dbdict/dbdict_run_sql.py	Thu Nov 13 18:40:45 2008 -0500
+++ b/pylearn/dbdict/dbdict_run_sql.py	Tue Nov 18 19:31:56 2008 -0500
@@ -291,16 +291,20 @@
 
         :returns: "<host>:<path>", of the sort used by ssh and rsync.
         """
-        path = os.path.join(
-                ':'.join([self.host, self.path]), 
-                self.dbname, 
-                self.tablename, 
-                self.id)
+        if self.host:
+            path = os.path.join(
+                    ':'.join([self.host, self.path]), 
+                    self.dbname, 
+                    self.tablename, 
+                    self.id)
+        else:
+            path = os.path.join(self.path, 
+                    self.dbname, self.tablename, self.id)
 
         if direction == 'push':
-            rsync_cmd = 'rsync -r * "%s"' % path
+            rsync_cmd = 'rsync -a * "%s/"' % path
         elif direction == 'pull':
-            rsync_cmd = 'rsync -r "%s/*" .' % path
+            rsync_cmd = 'rsync -a "%s/" .' % path
         else:
             raise Exception('invalid direction', direction)
 
@@ -315,13 +319,18 @@
         return self.rsync('push')
 
     def touch(self):
-        host = self.host
         path = os.path.join(self.path, self.dbname, self.tablename, self.id)
-        ssh_cmd = ('ssh %(host)s  "mkdir -p \'%(path)s\' && cd \'%(path)s\' '
-        '&& touch stdout stderr && mkdir -p workdir"' % locals())
-        ssh_rval = os.system(ssh_cmd)
-        if 0 != ssh_rval:
-            raise Exception('ssh failure', (ssh_rval, ssh_cmd))
+        if self.host:
+            host = self.host
+            touch_cmd = ('ssh %(host)s  "mkdir -p \'%(path)s\' && cd \'%(path)s\' '
+            '&& touch stdout stderr && mkdir workdir"' % locals())
+        else:
+            touch_cmd = ("mkdir -p '%(path)s' && cd '%(path)s' "
+            '&& touch stdout stderr && mkdir workdir' % locals())
+        print "ECHO", touch_cmd
+        touch_rval = os.system(touch_cmd)
+        if 0 != touch_rval:
+            raise Exception('touch failure', (touch_rval, touch_cmd))
 
     def delete(self):
         #something like ssh %s 'rm -Rf %s' should work, but it's pretty scary...
@@ -341,6 +350,9 @@
     except:
         exproot = os.getcwd()
 
+    if not exproot.startswith('/'):
+        exproot = os.path.join(os.getcwd(), exproot)
+
     #TODO: THIS IS A GOOD IDEA RIGHT?
     #   It makes module-lookup work based on cwd-relative paths
     #   But possibly has really annoying side effects?  Is there a cleaner