Commits

Taras KulaPard committed 6b5c07a

add custom before/after install/remove scripts

  • Participants
  • Parent commits 3ab4cb7

Comments (0)

Files changed (2)

 dist
 build
 packages
+scripts
 
 # switch to regexp syntax.
 syntax: regexp

File alexis/rhel.py

         self.run_deps = run_deps or []
         self.pkg_name = ('{0.prefix}-{0.app_name}'.format(self)).lower()
         self.base_path = '/tmp/{0.pkg_name}-{0.version}'.format(self)
-        self.app_path = os.path.join(self.base_path, self.prefix, app_name)
+        self.app_path = os.path.join(self.base_path, self.prefix, self.app_name)
         self.venv_path = os.path.join(self.app_path, 'venv')
         self.src_path = os.path.join(self.app_path, 'app')
         self.static_path = os.path.join(self.app_path, 'static')
     #                run('{} setup.py install'.format(os.path.join(self.venv_path, 'bin/python')))
 
     @with_settings(user='buildbot')
-    def build_rpm(self):
+    def build_rpm(
+            self,
+            before_remove=None,
+            after_remove=None,
+            before_install=None,
+            after_install=None
+
+    ):
         """
         Build RPM package.
         """
 
         with cd(self.base_path):
             # TODO: del creating empty folder
-            if not os.path.exists(os.path.join(self.src_path, 'rhel')):
-                run('mkdir {}'.format(os.path.join(self.src_path, 'rhel')))
+#            if not os.path.exists(os.path.join(self.src_path, 'rhel')):
+#                run('mkdir {}'.format(os.path.join(self.src_path, 'rhel')))
 
-            run('mv {} .'.format(os.path.join(self.src_path, 'rhel')))
-            #            self.run_deps.append('python-virtualenv')
+#            run('mv {} .'.format(os.path.join(self.src_path, 'rhel')))
+            self.run_deps.append('python-virtualenv')
             deps_str = '-d ' + ' -d '.join(self.run_deps)
-            hooks_str = ' '.join(
-                '{} {}'.format(opt, os.path.join('rhel', fname))
-                    for opt, fname in [
-                    ('--before-remove', 'prerm'),
-                    ('--after-remove', 'postrm'),
-                    ('--before-install', 'preinst'),
-                    ('--after-install', 'postinst'),
-                ]
-                    if os.path.exists(os.path.join('rhel', fname))
-            )
+            for file_path in [before_remove, after_remove, before_install, after_install]:
+                if file_path and os.path.exists(file_path):
+                    put(file_path, os.path.join(self.base_path, 'rhel/'))
+
             app_dir = os.path.join(self.prefix, self.app_name, 'app')
             venv_dir = os.path.join(self.prefix, self.app_name, 'venv')
             static_dir = os.path.join(self.prefix, self.app_name, 'static')
+
+            hooks_str = ' '.join(
+                '{} {}'.format(opt, os.path.join('rhel', os.path.basename(file_path)))
+                    for opt, file_path in [
+                    ('--before-remove', before_remove),
+                    ('--after-remove', after_remove),
+                    ('--before-install', before_install),
+                    ('--after-install', after_install),
+                ]
+                    if file_path and os.path.exists(file_path)
+            )
+
             app_deps_str = deps_str + ' -d "{0.pkg_name}-static >= {0.version}" -d "{0.pkg_name}-venv >= {0.version}"'.format(
                 self)
             venv_deps_str = deps_str
         run('hg clone {0.hg_repository} -r {0.hg_branch} {0.src_path}'.format(self))
 
     def create_virtualenv(self, python_path):
-        with cd('~'):
-            run('rm -f virtualenv.py*')
-        put('{}'.format(os.path.join(os.path.dirname(__file__), 'libs/virtualenv.py')), '~/')
+#        with cd('~'):
+#            run('rm -f virtualenv.py*')
+#        put('{}'.format(os.path.join(os.path.dirname(__file__), 'libs/virtualenv.py')), '~/')
         with cd(self.app_path):
             run('rm -rf venv')
-            run('{} ~/virtualenv.py venv'.format(python_path))
+            run('virtualenv venv --python={}'.format(python_path))
+#            run('{} ~/virtualenv.py venv'.format(python_path))