Support for configurable packaging directory
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 17 Aug 2012 13:58:10 +0000 (16:58 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 2 Nov 2012 08:46:51 +0000 (10:46 +0200)
Add config file parameter and command line option to specify the
packaging directory. Command line option takes preference over the
config file setting.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gitbuildsys/cmd_build.py
gitbuildsys/cmd_changelog.py
gitbuildsys/cmd_export.py
gitbuildsys/cmd_import.py
gitbuildsys/cmd_remotebuild.py
gitbuildsys/conf.py
gitbuildsys/utils.py
tools/gbs

index ae32307..e745f23 100644 (file)
@@ -29,7 +29,8 @@ import re
 from gitbuildsys import msger, utils, runner, errors
 from gitbuildsys.conf import configmgr
 from gitbuildsys.safe_url import SafeURL
-from gitbuildsys.cmd_export import transform_var_format_from_shell_to_python
+from gitbuildsys.cmd_export import transform_var_format_from_shell_to_python, \
+                                   get_packaging_dir
 
 from gbp.rpm.git import GitRepositoryError, RpmGitRepository
 
@@ -157,6 +158,7 @@ def prepare_depanneur_opts(args):
                         args.binary_list)
         cmd_opts += ['--binary=%s' % args.binary_list]
     cmd_opts += ['--threads=%s' % args.threads]
+    cmd_opts += ['--packaging-dir=%s' % get_packaging_dir(args)]
 
     return cmd_opts
 
index 9fdec40..fbcab0f 100644 (file)
@@ -27,6 +27,7 @@ import shutil
 
 from gitbuildsys import msger, utils
 from gitbuildsys.conf import configmgr
+from gitbuildsys.cmd_export import get_packaging_dir
 
 from gbp.rpm.git import GitRepositoryError, RpmGitRepository
 
@@ -89,7 +90,9 @@ def main(args):
 
     project_root_dir = repo.path
 
-    changes_file_list = glob.glob("%s/packaging/*.changes" % project_root_dir)
+    packaging_dir = get_packaging_dir(args)
+    changes_file_list = glob.glob("%s/%s/*.changes" % (project_root_dir,
+                                                       packaging_dir))
 
     if changes_file_list:
         fn_changes = changes_file_list[0]
@@ -98,7 +101,7 @@ def main(args):
                            % (changes_file_list[0]))
     else:
         # Create .changes file with the same name as a spec
-        specfile = utils.guess_spec(project_root_dir, args.spec)
+        specfile = utils.guess_spec(project_root_dir, packaging_dir, args.spec)
         fn_changes = os.path.splitext(specfile)[0] + ".changes"
 
     # get the commit start from the args.since
index 3e3c988..0562971 100644 (file)
@@ -55,6 +55,14 @@ def is_native_pkg(repo, args):
         upstream_branch = configmgr.get('upstream_branch', 'general')
     return not repo.has_branch(upstream_branch)
 
+def get_packaging_dir(args):
+    """
+    Determine the packaging dir to be used
+    """
+    if args.packaging_dir:
+        return args.packaging_dir
+    return configmgr.get('packaging_dir', 'general')
+
 def transform_var_format_from_shell_to_python(whole):
     '''replace string like ${xxx} with %(xxx)s'''
     return re.sub(r'\$\{([^}]+)\}', r'%(\1)s', whole)
@@ -88,7 +96,7 @@ def create_gbp_export_args(repo, commit, export_dir, tmp_dir, spec, args,
             "--git-upstream-branch=upstream",
             "--git-export-dir=%s" % export_dir,
             "--git-tmp-dir=%s" % tmp_dir,
-            "--git-packaging-dir=packaging",
+            "--git-packaging-dir=%s" % get_packaging_dir(args),
             "--git-spec-file=%s" % spec,
             "--git-export=%s" % commit,
             "--git-upstream-branch=%s" % upstream_branch,
@@ -171,12 +179,14 @@ def main(args):
     utils.git_status_checker(repo, args)
     workdir = repo.path
 
-    if not os.path.exists("%s/packaging" % workdir):
-        msger.error('No packaging directory, so there is nothing to export.')
+    packaging_dir = get_packaging_dir(args)
+    if not os.path.exists(os.path.join(workdir, packaging_dir)):
+        msger.error("No packaging directory '%s/', so there is nothing to "
+                    "export." % packaging_dir)
 
     # Only guess spec filename here, parse later when we have the correct
     # spec file at hand
-    specfile = utils.guess_spec(workdir, args.spec)
+    specfile = utils.guess_spec(workdir, packaging_dir, args.spec)
 
     outdir = "%s/packaging" % workdir
     if args.outdir:
index 71bee7e..64e0396 100644 (file)
@@ -21,6 +21,7 @@
 import os
 
 from gitbuildsys import msger
+from gitbuildsys.cmd_export import get_packaging_dir
 
 from gbp.scripts.import_srpm import main as gbp_import_srpm
 from gbp.scripts.import_orig_rpm import main as gbp_import_orig
@@ -35,7 +36,8 @@ def main(args):
 
     path = args.path
 
-    params = ["argv[0] placeholder", "--packaging-dir=packaging",
+    params = ["argv[0] placeholder",
+              "--packaging-dir=%s" % get_packaging_dir(args),
               "--upstream-branch=%s" % args.upstream_branch, path]
 
     if path.endswith('.src.rpm') or path.endswith('.spec'):
index 98585c7..2021d6c 100644 (file)
@@ -26,7 +26,7 @@ from gitbuildsys import msger, errors, utils
 
 from gitbuildsys.conf import configmgr, encode_passwd
 from gitbuildsys.oscapi import OSC, OSCError
-from gitbuildsys.cmd_export import export_sources
+from gitbuildsys.cmd_export import export_sources, get_packaging_dir
 from gitbuildsys.cmd_build import get_profile
 
 import gbp.rpm
@@ -81,11 +81,12 @@ def main(args):
         utils.git_status_checker(repo, args)
 
     # TODO: check ./packaging dir at first
-    specs = glob.glob('%s/packaging/*.spec' % workdir)
+    packaging_dir = get_packaging_dir(args)
+    specs = glob.glob('%s/%s/*.spec' % (workdir, packaging_dir))
     if not specs:
-        msger.error('no spec file found under /packaging sub-directory')
+        msger.error("no spec file found under './%s'" % packaging_dir)
 
-    specfile = utils.guess_spec(workdir, args.spec)
+    specfile = utils.guess_spec(workdir, packaging_dir, args.spec)
     # get 'name' and 'version' from spec file
     try:
         spec = gbp.rpm.parse_spec(specfile)
index cb2cbc5..bd2067a 100644 (file)
@@ -189,6 +189,7 @@ class ConfigMgr(object):
                 'upstream_tag': 'upstream/${upstreamversion}',
                 'squash_patches_until': '',
                 'buildroot':    '~/GBS-ROOT/',
+                'packaging_dir': 'packaging',
             },
     }
 
index 9879f92..11a27fb 100644 (file)
@@ -43,7 +43,7 @@ class Workdir(object):
     def __exit__(self, _type, _value, _tb):
         os.chdir(self._cwd)
 
-def guess_spec(workdir, default_spec):
+def guess_spec(workdir, packaging_dir, default_spec):
     workdir = os.path.abspath(workdir)
     git_project =  os.path.basename(workdir)
 
@@ -56,11 +56,12 @@ def guess_spec(workdir, default_spec):
             msger.error('%s does not exit' % default_spec)
         return default_spec
 
-    specfile = os.path.join(workdir, 'packaging', '%s.spec' % git_project)
+    specfile = os.path.join(workdir, packaging_dir, '%s.spec' % git_project)
     if not os.path.exists(specfile):
-        specs = glob.glob(os.path.join(workdir, 'packaging', '*.spec'))
+        specs = glob.glob(os.path.join(workdir, packaging_dir, '*.spec'))
         if not specs:
-            msger.error('no spec file found under %s/packaging' % workdir)
+            msger.error('no spec file found under %s/%s' % (workdir,
+                                                            packaging_dir))
 
         if len(specs) > 1:
             msger.error("Can't decide which spec file to use.")
index b4f4dc4..6816276 100755 (executable)
--- a/tools/gbs
+++ b/tools/gbs
@@ -54,6 +54,8 @@ def import_parser(parser):
                         help='specify upstream branch for new package version')
     parser.add_argument('--no-merge', action='store_true',
                          help='don\'t merge new upstream branch to master')
+    parser.add_argument('--packaging-dir',
+                        help='directory containing packaging files')
 
     parser.set_defaults(alias="im")
     return parser
@@ -89,6 +91,8 @@ def export_parser(parser):
                          'to given commit-ish into one monolithic diff file. '
                          'Format is the commit-ish optionally followed by a '
                          'colon and diff filename base.')
+    parser.add_argument('--packaging-dir',
+                        help='directory containing packaging files')
 
     parser.set_defaults(alias="ex")
     return parser
@@ -161,6 +165,8 @@ def build_parser(parser):
                         'to given commit-ish into one monolithic diff file. '
                         'Format is the commit-ish optionally followed by a '
                         'colon and diff filename base.')
+    parser.add_argument('--packaging-dir',
+                        help='directory containing packaging files')
 
     # depanneur special options
     parser.add_argument('--clean-once', action='store_true',
@@ -248,6 +254,8 @@ def remotebuild_parser(parser):
                         'given commit-ish into one monolithic diff file. '
                         'Format is the commit-ish optionally followed by a '
                         'colon and diff filename base.')
+    parser.add_argument('--packaging-dir',
+                        help='directory containing packaging files')
 
     parser.set_defaults(alias="rb")
     return parser
@@ -291,6 +299,8 @@ def changelog_parser(parser):
                         help='commit to start from')
     parser.add_argument('-m', '--message',
                         help='use given message as the changelog entry')
+    parser.add_argument('--packaging-dir',
+                        help='directory containing packaging files')
     parser.set_defaults(alias='ch')
     return parser