Julien Jehannet avatar Julien Jehannet committed a801d59

improve default init process (merge config)

Comments (0)

Files changed (7)

+# HG changeset patch
+# Parent 215e497a8e83a211bfbf0a4e8bdce9b0494d1d9a
+diff --git a/lgp/build.py b/lgp/build.py
+--- a/lgp/build.py
++++ b/lgp/build.py
+@@ -25,6 +25,8 @@ import os.path as osp
+ from subprocess import Popen
+ from multiprocessing import Process, cpu_count, BoundedSemaphore
+ 
++from debian import deb822
++
+ from logilab.devtools.lgp import (LGP, CONFIG_FILE, HOOKS_DIR, utils)
+ from logilab.devtools.lgp.exceptions import LGPException
+ from logilab.devtools.lgp.utils import build_context
+@@ -38,7 +40,9 @@ from logilab.devtools.lgp.clean import C
+ @LGP.register
+ class Builder(SetupInfo):
+     """Provides functions to build a debian package for a python package
+-    You can change options in /etc/lgp/lgprc inside the [LGP-BUILD] section
++    You can change options in /etc/lgp/lgprc inside the [BUILD] section
++
++    lgp build --help for more details.
+     """
+     name = "build"
+     options = DscBuilder.options + [
+@@ -50,6 +54,12 @@ class Builder(SetupInfo):
+                  'help': "run in parallel with a max limit of processes",
+                  'group': 'Build',
+                 }),
++               ('dscfile',
++                {'type': 'string',
++                 'dest' : "dscfile",
++                 'help': 'use a specific Debian source file (.dsc) instead of recreating it',
++                 'group': 'Build'
++                }),
+                ('debug',
+                 {'type': 'csv',
+                   'dest': 'debug_hooks',
+@@ -89,35 +99,50 @@ class Builder(SetupInfo):
+             raise LGPException(msg)
+ 
+     def guess_environment(self):
++        self.config.orig_tarball = self._normpath(self.config.orig_tarball)
++        self.config.dscfile = self._normpath(self.config.dscfile)
++        
++        if self.config.orig_tarball:
++            self.logger.info('use original source archive (tarball): %s',
++                             self.config.orig_tarball)
++        if self.config.dscfile:
++            self.logger.info('use the Debian source control file: %s',
++                             self.config.dscfile)
++            contents = deb822.Deb822(file(self.config.dscfile))
++            self.config.archi = contents["Architecture"]
++        
+         # if no default value for distribution, use list from existing images
+         if self.config.distrib is None:
+             self.config.distrib = 'all'
+         super(Builder, self).guess_environment()
+ 
+     def run(self, args):
+-        Cleaner(None).run(args)
++        Cleaner().run(args)
++        
++        jobs = self.config.jobs > 0 and self.config.jobs or 1
++        self.available_procs = BoundedSemaphore(jobs)
++        
++        if utils.is_architecture_independent():
++            arch= self.get_architectures(['current'])[0]
++            msg = ('this binary build is arch-independent. Lgp will '
++                   'only build on current architecture (%s)')
++            self.logger.info(msg, arch)
+         
+         with build_context(self.config.keep_tmpdir) as tmpdir:
+-            pristine_tarball = Pristine(None).make_orig_tarball(tmpdir)
+-
+-            jobs = self.config.jobs > 0 and self.config.jobs or 1
+-            self.available_procs = BoundedSemaphore(jobs)
+-
+-            dsc_builder = DscBuilder(None)
+-            dsc_builder.config.pkg_dir = self.config.pkg_dir # XXX
+-
+-            if utils.is_architecture_independent():
+-                arch= self.get_architectures(['current'])[0]
+-                msg = ('this binary build is arch-independent. Lgp will '
+-                       'only build on current architecture (%s)')
+-                self.logger.info(msg, arch)
+-
++            pristine = Pristine(config=self.config)
++            pristine_tarball = pristine.make_orig_tarball(tmpdir=tmpdir)
++            if self.config.dscfile is None:
++                dsc_builder = DscBuilder(config=self.config)
++            
+             for distrib in self.distributions:
+-                dscfile = dsc_builder.make_debian_source_package(pristine_tarball, distrib,
+-                                                                 tmpdir=tmpdir)
+-                self.make_debian_binary_package(dscfile, distrib, tmpdir=tmpdir)
+-            self.logger.info("start parallel binary build(s) in background (limit: %s) ...",
+-                             jobs)
++                if self.config.dscfile is None:
++                    make_dsc = dsc_builder.make_debian_source_package
++                    self.config.dscfile = make_dsc(pristine_tarball, distrib, tmpdir=tmpdir)
++                self.make_debian_binary_package(self.config.dscfile, distrib, tmpdir=tmpdir)
++            
++            if len(self.joblist)>1:
++                msg = "start parallel binary build(s) in background (limit: %s) ..."
++                self.logger.info(msg, jobs)
+             
+             # waiting for all child processes
+             [p.join() for p in self.joblist]
+@@ -152,7 +177,8 @@ class Builder(SetupInfo):
+             build['builddir'] = os.path.join(tmpdir, build['distrib'], build['arch'])
+             build['dscfile'] = dscfile
+ 
+-            os.mkdir(build['builddir'])
++            # multi-level creation needed if no source package
++            os.makedirs(build['builddir'])
+             self._build_tmpdirs.append(build['builddir'])
+ 
+             p = Process(name="%s/%s" % (build['distrib'], build['arch']),

build_pristine.diff

+# HG changeset patch
+# Parent 7214b51d70bb5fe98f4cb1b83f4a833e15a9f659
+diff --git a/lgp/build_pristine.py b/lgp/build_pristine.py
+--- a/lgp/build_pristine.py
++++ b/lgp/build_pristine.py
+@@ -37,12 +37,13 @@ class Pristine(SetupInfo):
+     """
+     name = "build-pristine"
+     options = SetupInfo.options + [
+-               ('orig-tarball',
++               ('pristine-tarball',
+                 {'type': 'string',
+                  'default' : None,
+                  'dest': 'orig_tarball',
+                  'metavar' : "<tarball>",
+-                 'help': "URI to orig.tar.gz file",
++                 'help': "URI to pristine tarball orig.tar.gz file",
++                 'group': 'Build',
+                 }),
+                ('keep-tmpdir',
+                 {'action': 'store_true',
+@@ -57,15 +58,15 @@ class Pristine(SetupInfo):
+     def guess_environment(self): pass
+ 
+     def run(self, args):
+-        Cleaner(None).run(args)
++        Cleaner().run(args)
+         with build_context(self.config.keep_tmpdir) as tmpdir:
+-            pristine_tarball = self.make_orig_tarball(tmpdir)
++            pristine_tarball = self.make_orig_tarball(tmpdir=tmpdir)
+             fullpath = osp.join('..', osp.basename(pristine_tarball))
+             cp(pristine_tarball, fullpath)
+         msg= 'a new original source archive (tarball) is available: %s'
+         self.logger.info(msg, fullpath)
+ 
+-    def make_orig_tarball(self, tmpdir):
++    def make_orig_tarball(self, tmpdir=None):
+         """make or retrieve upstream pristine tarballs
+ 
+         Start by calling the optional get-orig-source from debian/rules

build_source.diff

+# HG changeset patch
+# Parent 83019fafb4a548096216705e65d7238fd09ea5fa
+diff --git a/lgp/build_source.py b/lgp/build_source.py
+--- a/lgp/build_source.py
++++ b/lgp/build_source.py
+@@ -70,16 +70,23 @@ class DscBuilder(SetupInfo):
+     packages = []
+ 
+     def guess_environment(self):
++        self.config.orig_tarball = self._normpath(self.config.orig_tarball)
++        
++        if self.config.orig_tarball:
++            self.logger.info('use original source archive (tarball) is available: %s',
++                             self.config.orig_tarball)
++        
+         # if no default value for distribution, try to retrieve it from changelog
+         if self.config.distrib is None or 'changelog' in self.config.distrib:
+             self.config.distrib = 'changelog'
+         super(DscBuilder, self).guess_environment()
+ 
+     def run(self, args):
+-        Cleaner(None).run(args)
++        Cleaner().run(args)
+ 
+         with utils.build_context(self.config.keep_tmpdir) as tmpdir:
+-            pristine_tarball = Pristine(None).make_orig_tarball(tmpdir)
++            pristine = Pristine(config=self.config)
++            pristine_tarball = pristine.make_orig_tarball(tmpdir=tmpdir)
+ 
+             for distrib in self.distributions:
+                 resultdir = self.get_distrib_dir(distrib)

lgp-hook-autoshell.diff

 # HG changeset patch
-# Date 1304553077 -7200
+# Date 1304594777 -7200
 # User Julien Jehannet <julien@smaf.org>
 # Parent 7519ed15d99adc2eb15ffe3accdd439c4bdcc4bb
 lgp: new C90autoshell hook to enter into debug shell
 diff --git a/lgp/build.py b/lgp/build.py
 --- a/lgp/build.py
 +++ b/lgp/build.py
-@@ -42,6 +42,7 @@ class Builder(SetupInfo):
+@@ -42,12 +42,30 @@ class Builder(SetupInfo):
      """
      name = "build"
      options = DscBuilder.options + [
-+               # XXX should be enabled by default ?
-                ('hooks',
-                 {'type': 'string',
-                  'default': '', # check if new HOOKS_DIR
-@@ -65,6 +66,15 @@ class Builder(SetupInfo):
-                  'help': "run in parallel with a max limit of processes",
-                  'group': 'Build',
-                 }),
++               ('jobs',
++                {'type': 'int',
++                 'default': cpu_count(),
++                 'short': 'j',
++                 'dest' : "jobs",
++                 'help': "run in parallel with a max limit of processes",
++                 'group': 'Build',
++                }),
 +               ('debug',
 +                {'type': 'csv',
 +                  'dest': 'debug_hooks',
 +                          "(available action: autoshell)",
 +                 'group': 'Pbuilder',
 +                }),
++               # XXX should be enabled by default ?
+                ('hooks',
+                 {'type': 'string',
+                  'default': '', # check if new HOOKS_DIR
+                  'dest' : "hooks",
+-                 'help': ("run pbuilder hooks from '%s' directory or give "
+-                          "'NO' if no hook must be executed" % HOOKS_DIR),
++                 'help': ("use yes/no to run pbuilder hooks in given directory."
++                          "You can also pass your own hook directory (default: %s)" % HOOKS_DIR),
+                  'group': 'Pbuilder'
+                 }),
+                ('post-treatments',
+@@ -57,14 +75,6 @@ class Builder(SetupInfo):
+                  'help': "run embedded post-treatments: add trivial repository",
+                  'group': 'Debian'
+                 }),
+-               ('jobs',
+-                {'type': 'int',
+-                 'default': cpu_count(),
+-                 'short': 'j',
+-                 'dest' : "jobs",
+-                 'help': "run in parallel with a max limit of processes",
+-                 'group': 'Build',
+-                }),
                ]
      # list of all temporary directories
      _build_tmpdirs = []

lgp-sign-process.diff

                   'dest' : "sign",
                   'help': "try to sign Debian package(s) just built",
 -                 'group': 'Debian'
-+                 'group': 'Build'
++                 'group': 'Debian'
                  }),
                ]
  
 lgp-sign-process.diff
 lgp-hook-autoshell.diff
 DEBUG_LGP_STUFF_WITH_LOCAL_CONFIGURATION
+setupinfo.diff
+build.diff
+build_pristine.diff
+build_source.diff
 TODOLIST
 wip-lgp-build-source-improve.diff
 wip-login-x11.diff
+# HG changeset patch
+# Date 1304606876 -7200
+# User Julien Jehannet <julien@smaf.org>
+# Parent e7ee937dd3b5f9f9133589c942094d1ce82d9ba0
+
+diff --git a/lgp/setupinfo.py b/lgp/setupinfo.py
+--- a/lgp/setupinfo.py
++++ b/lgp/setupinfo.py
+@@ -107,7 +107,7 @@ class SetupInfo(clcommands.Command):
+                 }),
+               ]
+ 
+-    def __init__(self, logger):
++    def __init__(self, logger=None, config=None):
+         self.isatty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
+         options = [('quiet',
+                     {'action': 'count',
+@@ -153,8 +153,11 @@ class SetupInfo(clcommands.Command):
+                     }),
+                   ]
+         self.options.extend(options) # merge parent options
+-        logger = logging.getLogger(self.name)
++        if logger is None:
++            logger = logging.getLogger(self.name)
+         super(SetupInfo, self).__init__(logger)
++        if config:
++            self.config._update(vars(config), mode="careful")
+         self._set_package_format()
+         exitcode = os.EX_OK
+ 
+@@ -206,7 +209,12 @@ class SetupInfo(clcommands.Command):
+         return self.exitcode
+ 
+     def go_into_package_dir(self, arguments):
+-        """go into package directory"""
++        """go into package directory
++        
++        .. note::
++            current directory wil be saved in `old_current_directory`
++        """
++        self.old_current_directory = os.getcwd() # use for relative filename in parameters
+         if arguments:
+             if os.path.exists(arguments[0]):
+                 self.config.pkg_dir = osp.abspath(arguments[0])
+@@ -217,8 +225,8 @@ class SetupInfo(clcommands.Command):
+             os.chdir(self.config.pkg_dir)
+             self.logger.debug('change the current working directory to: %s' % self.config.pkg_dir)
+         else:
+-            self.config.pkg_dir = os.getcwd()
+-
++            self.config.pkg_dir = self.old_current_directory
++        
+         # FIXME Keep working relative pathnames provided in line arguments after chdir
+         if getattr(self.config, "orig_tarball", None) and osp.exists(self.config.orig_tarball):
+             # we use osp.exists to rewrite only with valid path name
+@@ -232,7 +240,7 @@ class SetupInfo(clcommands.Command):
+                              'targeted architectures. Consider using the "any" keyword '
+                              'to force the build on all architectures or let lgp finds '
+                              'the value in debian/changelog by itself in doubt.')
+-            self.logger.warn('lgp replaces "all" with "current" architecture value for this command')
++            self.logger.warn('lgp replaces "all" architecture value by "current" for the build')
+ 
+         # Define mandatory attributes for lgp commands
+         self.architectures = utils.get_architectures(self.config.archi,
+@@ -248,7 +256,10 @@ class SetupInfo(clcommands.Command):
+         setup_file must not be redefine since we can call this
+         method several times
+         """
+-        setup_file = self.config.setup_file
++        setup_file = self.config.setup_file = self._normpath(self.config.setup_file)
++        if setup_file:
++            self.logger.info('use specific setup file: %s', setup_file)
++        
+         if osp.isfile('__pkginfo__.py') and not setup_file:
+             # Logilab's specific format
+             # FIXME Format is buggy if setup_file was set to 'setup.py'
+@@ -521,3 +532,12 @@ class SetupInfo(clcommands.Command):
+                 raise
+         return distrib_dir
+ 
++    def _normpath(self, path):
++        """XXX could be coded and done directly by option checker (optparse)"""
++        if path:
++            assert self.old_current_directory
++            path = osp.abspath(osp.join(self.old_current_directory,
++                                          osp.expanduser(path)))
++            assert osp.exists(path), "'%s' not found" % path
++        return path
++
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.