Commits

Vladimir Mihailenco committed 3001dc9

Add push_files task

Comments (0)

Files changed (1)

 import os
 
-from fabric.api import local, run, put, cd
+from fabric.api import local, run, put, lcd, cd
 
 from .containers import conf
 from .task import Task
 
 
-__all__ = ['push']
+__all__ = ['push', 'push_files']
 
 
-class Push(Task):
-    @conf
-    def exclude_string(self):
-        excludes = ['*.pyc', '*.pyo']
-        exclude_string = ' '.join(['--exclude "%s"' % pattern
-                                   for pattern in excludes])
-
-        if os.path.exists('%(src_path)s/.excludes' % self.conf):
-            exclude_string = '--exclude-from .excludes ' + exclude_string
-
-        return exclude_string
-
+class PushTask(Task):
     @conf
     def src_file(self):
         if 'src_file' not in self.conf:
                 '%(target_path)s/fabdeploy_%(current_time)s.tar' % self.conf
         return self.conf.target_file
 
+
+class Push(PushTask):
+    @conf
+    def exclude_string(self):
+        excludes = ['*.pyc', '*.pyo']
+        exclude_string = ' '.join(['--exclude "%s"' % pattern
+                                   for pattern in excludes])
+
+        if os.path.exists('%(src_path)s/.excludes' % self.conf):
+            exclude_string = '--exclude-from .excludes ' + exclude_string
+
+        return exclude_string
+
     def do(self):
         local('tar %(exclude_string)s '
               '--create '
             run('rm %(target_file)s' % self.conf)
 
 push = Push()
+
+
+class PushFiles(PushTask):
+    def do(self):
+        if isinstance(self.conf.files, list):
+            files = self.conf.files
+        else:
+            files = [f.strip() for f in self.conf.files.split(',')]
+        self.conf._files = '--add-file ' + '--add-file '.join(files)
+
+        with lcd(self.conf.src_path):
+            local(
+                'tar '
+                '--create '
+                '--gzip '
+                '--file %(src_file)s '
+                '%(_files)s' % self.conf)
+        put(self.conf.src_file, self.conf.target_file)
+        local('rm %(src_file)s' % self.conf)
+        with cd(self.conf.target_path):
+            run('tar '
+                '--extract '
+                '--gunzip '
+                '--file %(target_file)s' % self.conf)
+            run('rm %(target_file)s' % self.conf)
+
+push_files = PushFiles()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.