[ckan-changes] commit/ckan-debs-public: dread: First draft of deb builder and builderconfig.

Bitbucket commits-noreply at bitbucket.org
Tue Jun 7 10:50:12 UTC 2011


1 new changeset in ckan-debs-public:

http://bitbucket.org/okfn/ckan-debs-public/changeset/018326ceee99/
changeset:   018326ceee99
branches:    
user:        dread
date:        2011-06-07 12:49:53
summary:     First draft of deb builder and builderconfig.
affected #:  6 files (12.1 KB)

--- a/ckan-dgu/DEBIAN/control	Thu May 26 20:51:45 2011 +0100
+++ b/ckan-dgu/DEBIAN/control	Tue Jun 07 11:49:53 2011 +0100
@@ -1,9 +1,9 @@
 Package: ckan-dgu
 Version: 0.2~16
-Architecture: amd64
+Architecture: all
 Maintainer: James Gardner <james.gardner at okfn.org>
 Installed-Size: 0
-Depends: python-ckan, apache2, libapache2-mod-wsgi, python-apachemiddleware, ckan, python-ckanext-dgu, python-ckanext-harvest, python-ckanext-csw, python-swiss, python-dateutil, rabbitmq-server, postgresql-8.4-postgis, python-carrot, python-ckanext-spatial, python-ckanext-inspire, python-ckanext-qa
+Depends: python-ckan (>= 1.4), apache2, libapache2-mod-wsgi, python-apachemiddleware, python-ckanext-dgu, python-ckanext-harvest, python-ckanext-csw, python-swiss, python-dateutil, rabbitmq-server, postgresql-8.4-postgis, python-carrot, python-ckanext-spatial, python-ckanext-inspire, python-ckanext-qa, python-ckanext-
 Section: main/web
 Priority: extra
 Homepage: http://ckan.org


--- a/ckan-dgu/DEBIAN/postinst	Thu May 26 20:51:45 2011 +0100
+++ b/ckan-dgu/DEBIAN/postinst	Tue Jun 07 11:49:53 2011 +0100
@@ -187,7 +187,7 @@
 #           the ckan-dgu package is upgraded
 # QUESTION: Should email reports be sent to root?
 # Gov Daily
-# 31               23  *   *   *   python /usr/lib/pymodules/python2.6/ckanext/dgu/bin/gov-daily.py /etc/ckan/dgu/dgu.ini
+# 31               23  *   *   *   python /usr/lib/pymodules/python2.6/ckanext/dgu/bin/gov_daily.py /etc/ckan/dgu/dgu.ini
 # Try to start the harvester consumers in case they have stopped
 */10              *  *   *   *   /etc/init.d/dgu_harvest_gather start
 */10              *  *   *   *   /etc/init.d/dgu_harvest_fetch start


--- a/deb.py	Thu May 26 20:51:45 2011 +0100
+++ b/deb.py	Tue Jun 07 11:49:53 2011 +0100
@@ -39,130 +39,193 @@
 
 import os 
 import sys
-from subprocess import Popen
+from subprocess import Popen, check_call, CalledProcessError
 
-def create_debian(package, version, here):
-    process = Popen("""
-        export EDITOR="vi"
-        export DEBFULLNAME="James Gardner"
-        export DEBEMAIL="james.gardner at okfn.org"
-        mv "%(package)s" "%(package)s-%(version)s"
-        tar -cvzf "%(package)s-%(version)s.tar.gz" "%(package)s-%(version)s"
-        mv "%(package)s-%(version)s" "%(package)s"
-        mv "%(package)s-%(version)s.tar.gz" "%(here)s"
-        cd "%(here)s"
-        tar -xf "%(package)s-%(version)s.tar.gz"
-        mv "%(package)s-%(version)s" "python-%(package)s-%(version)s"
-        cd "python-%(package)s-%(version)s"
-        echo "\n" | dh_make  -s -b -f "../%(package)s-%(version)s.tar.gz"
-        cd debian
-        rm *ex *EX
-        rm README.Debian
-        rm README.source
-        """%dict(
-            package=package, 
-            version=version, 
-            here=here,
-        ),
-        shell=True,
-    )
-    process.communicate()
-    return process.wait()
+class DebBuilder(object):
+    def __init__(self, **env):
+        '''
+        @params
+        package_path - full path to the package to be packaged up (contains setup.py)
+        package - name of package
+        version - version number e.g. 0.1~04+lucid
+        homepage - homepage (goes into control file)
+        deps - names of debian packages that this one depends on
+        base - debian diretory in output directory
+        here - output directory
+        print_prefix - Prefix for print statements
+        '''
+        for param in ['package_path', 'package', 'version', 'here', 'base',
+                       'homepage', 'deps']:
+            assert param in env, 'Need to specify param %r' % param
+        if env['deps']:
+            assert isinstance(env['deps'], (list, tuple))
+        if not env.has_key('print_prefix'):
+            env['print_prefix'] = '\n #'
+        self.env = env
+        
+    def run(self, cmd, cwd=None):
+        '''Runs a command, substituting env variables.
+        Non-zero returncode raises CalledProcessError
+        '''
+        print '%s Deb: %s' % (self.env['print_prefix'], cmd % self.env)
+        if cwd:
+            print 'With cwd: %s' % cwd % self.env
+        process = check_call(cmd % self.env,
+                             shell=True,
+                             cwd=(cwd % self.env) if cwd else None)
+    
+    def create_debian(self):
+        '''
+        Takes some source code and puts it into a debian directory suitable
+        for packaging up. Caller must ensure CWD is one up from the package
+        source
 
-def update_rules(base):
-    fp = open(os.path.join(base, 'rules'), 'wb')
-    control = fp.write("""\
-#!/usr/bin/make -f
+        Takes:
+          (package_path)/setup.py
 
-DEB_PYTHON_SYSTEM=pysupport
+        Creates:
+          (here)/(package)-(version).tar.gz
+          (here)/python-(package)-(version)/debian/*
 
-include /usr/share/cdbs/1/rules/debhelper.mk
-include /usr/share/cdbs/1/class/python-distutils.mk""")
-    fp.close()
+        environment params:
+        package_path - full path to the package (contains setup.py)
+        package - name of package to be packaged up
+        version - version number e.g. 0.1~04+lucid
+        here - output directory
 
-def update_change_log(base):
-    process = Popen("""
-        export DEBFULLNAME="James Gardner"
-        export DEBEMAIL="james.gardner at okfn.org"
-        dch -e
-        """, 
-        shell=True,
-        cwd=base,
-    )
-    process.communicate()
-    return process.wait()
+        '''
+        assert os.path.exists(self.env['package_path'])
+        assert os.path.exists(os.path.join(self.env['package_path'], 'setup.py')), 'Could not find %r' % os.path.join(self.env['package_path'], 'setup.py')
+        self.env['package_parent_path'], self.env['original_package_folder'] = os.path.split(os.path.normpath(self.env['package_path']))
+        assert not os.path.exists("%(package_parent_path)s/%(package)s-%(version)s" % self.env), 'Folder in the way: %r' % '%(package_parent_path)s/%(package)s-%(version)s' % self.env
+        self.run('mv "%(original_package_folder)s" "%(package)s-%(version)s"', '%(package_parent_path)s')
+        try:
+            self.run('tar -cvzf "%(here)s/%(package)s-%(version)s.tar.gz" "%(package)s-%(version)s"', '%(package_parent_path)s')
+        finally:
+            self.run('mv "%(package)s-%(version)s" "%(original_package_folder)s"', '%(package_parent_path)s')
+#        self.run('mv "%(package)s-%(version)s.tar.gz" "%(here)s"')
+        self.run('tar -xf "%(package_parent_path)s/%(package)s-%(version)s.tar.gz" -C %(here)s')
+        self.run('mv "%(package)s-%(version)s" "python-%(package)s-%(version)s"', '%(here)s')
+        self.run("""export EDITOR="vi"
+                    export DEBFULLNAME="James Gardner"
+                    export DEBEMAIL="james.gardner at okfn.org"
+                    cd %(here)s/python-%(package)s-%(version)s
+                    dh_make -s -b -f "../%(package)s-%(version)s.tar.gz"
+                    """)
+        self.run('rm %(base)s/*ex')
+        self.run('rm %(base)s/*EX')
+        self.run('rm %(base)s/README.Debian')
+        self.run('rm %(base)s/README.source')
 
-def build(base):
-    process = Popen("""
-        export DEBFULLNAME="James Gardner"
-        export DEBEMAIL="james.gardner at okfn.org"
-        debuild -us -uc
-        """, 
-        shell=True,
-        cwd=base,
-    )
-    process.communicate()
-    return process.wait()
+##        process = check_call("""
+##            export EDITOR="vi"
+##            export DEBFULLNAME="James Gardner"
+##            export DEBEMAIL="james.gardner at okfn.org"
+##            mv "%(package)s" "%(package)s-%(version)s"
+##            tar -cvzf "%(package)s-%(version)s.tar.gz" "%(package)s-%(version)s"
+##            mv "%(package)s-%(version)s" "%(package)s"
+##            mv "%(package)s-%(version)s.tar.gz" "%(here)s"
+##            cd "%(here)s"
+##            tar -xf "%(package)s-%(version)s.tar.gz"
+##            mv "%(package)s-%(version)s" "python-%(package)s-%(version)s"
+##            cd "python-%(package)s-%(version)s"
+##            echo "\n" | dh_make  -s -b -f "../%(package)s-%(version)s.tar.gz"
+##            cd debian
+##            rm *ex *EX
+##            rm README.Debian
+##            rm README.source
+##            """%dict(
+##                package=package, 
+##                version=version, 
+##                here=here,
+##            ),
+##            shell=True,
+##        )
+##        process.communicate()
+##        return process.wait()
 
-def cleanup(base, package, version):
-    process = Popen("""
-        cd ../../
-        rm -rf "python-%(package)s-%(version)s"
-        rm "python-%(package)s-%(version)s.tar.gz"
-        mv "python-%(package)s_%(version)s.orig.tar.gz" "python-%(package)s-%(version)s.tar.gz"
-        """%dict(
-            package=package, 
-            version=version, 
-        ), 
-        shell=True,
-        cwd=base,
-    )
-    process.communicate()
-    return process.wait()
+    def update_rules(self):
+        fp = open(os.path.join(self.env['base'], 'rules'), 'wb')
+        control = fp.write("""\
+    #!/usr/bin/make -f
 
-def update_control(base, package, version, homepage, deps):
-    fp = open(os.path.join(base, 'control'), 'r')
-    control = fp.read().split('\n')
-    fp.close()
-    control[1] = 'Section: main/web'
-    control[6] = 'Homepage: %s'%homepage
-    control[4] = 'Build-Depends: cdbs (>= 0.4.49), debhelper (>= 7), python (>= 2.5), python-support'
-    control.insert(5, 'XS-Python-Version: >= 2.5')
-    control[11] = 'Depends: ${misc:Depends}, ${python:Depends}'
-    control.insert(12, 'Recommends: ')
-    for dep in deps[:1]:
-        control[12] += dep
-    for dep in deps[1:]:
-        control[12] += ', '+dep
-    control[13] = 'Description: %s'%(package[:60])
-    control = control[:14]
-    fp = open(os.path.join(base, 'control'), 'wb')
-    control = fp.write('\n'.join(control))
-    fp.close()
+    DEB_PYTHON_SYSTEM=pysupport
 
-def handle_one(
-    package,
-    version,
-    homepage,
-    deps,
-    base,
-    here,
-):
-    create_debian(package, version, here)
-    update_control(base, package, version, homepage, deps)
-    update_rules(base)
-    #update_change_log(base)
-    build(base)
-    #cleanup(base, package, version)
+    include /usr/share/cdbs/1/rules/debhelper.mk
+    include /usr/share/cdbs/1/class/python-distutils.mk""")
+        fp.close()
+
+    def update_change_log(self):
+        self.run("""
+            export DEBFULLNAME="James Gardner"
+            export DEBEMAIL="james.gardner at okfn.org"
+            dch -e
+            """, 
+                 cwd=self.env['base'],
+                )
+
+    def build(self):
+        self.run("""
+            export DEBFULLNAME="James Gardner"
+            export DEBEMAIL="james.gardner at okfn.org"
+            debuild -us -uc
+            """,
+                 cwd=self.env['base'],
+                 )
+
+    def cleanup(self):
+        self.run('rm -rf "%(here)s/python-%(package)s-%(version)s"')
+        self.run('rm -rf "%(here)s/python-%(package)s-%(version)s.tag.gz"')
+        self.run('mv "%(here)s/python-%(package)s-%(version)s.orig.tag.gz" "%(here)s/python-%(package)s-%(version)s.tag.gz"')
+
+    def update_control(self):
+        control_filepath = os.path.join(self.env['base'], 'control')
+        fp = open(control_filepath, 'r')
+        control = fp.read().split('\n')
+        fp.close()
+        control[1] = 'Section: main/web'
+        control[6] = 'Homepage: %(homepage)s' % self.env
+        control[4] = 'Build-Depends: cdbs (>= 0.4.49), debhelper (>= 7), python (>= 2.5), python-support'
+        control.insert(5, 'XS-Python-Version: >= 2.5')
+        control[11] = 'Depends: ${misc:Depends}, ${python:Depends}'
+        deps_str = ', '.join(self.env['deps'] or '')
+        control.insert(12, 'Recommends: %s' % deps_str)
+        control[13] = 'Description: %s'%(self.env['package'][:60])
+        control = control[:14]
+        fp = open(control_filepath, 'wb')
+        control = fp.write('\n'.join(control))
+        fp.close()
+
+    def handle_one(self):
+        '''
+        Takes some source code and puts it into a debian directory suitable
+        for packaging up.
+
+        @return success boolean
+
+        '''
+        try:
+            self.create_debian()
+            self.update_control()
+            self.update_rules()
+            self.update_change_log()
+            self.build()
+            self.cleanup()
+        except CalledProcessError, e:
+            print 'Command failed'
+            return False
 
 if __name__ == '__main__':
-
+    db = DebBuilder(
+                    package_path=os.getcwd(),
+                    package=sys.argv[2],
+                    version=sys.argv[3],
+                    homepage=sys.argv[4],
+                    deps=sys.argv[5:],
+                    base=os.path.join(os.getcwd(), 'python-%s-%s' % (sys.argv[2], sys.argv[3]), 'debian'),
+                    here=os.getcwd(),
+                    )
     os.chdir(sys.argv[1])
-    handle_one(
-        package = sys.argv[2],
-        version = sys.argv[3],
-        homepage = sys.argv[4],
-        deps = sys.argv[5:],
-        base = os.path.join(os.getcwd(), 'python-%s-%s' % (sys.argv[2], sys.argv[3]), 'debian'),
-        here = os.getcwd(),
-    )
+    if not db.handle_one():
+        sys.exit(1)
+

Repository URL: https://bitbucket.org/okfn/ckan-debs-public/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list