]> git.donarmstrong.com Git - neurodebian.git/blobdiff - tools/blends-inject
Also for stats report which repo and which job number use our setup
[neurodebian.git] / tools / blends-inject
index 083b1e6fe97b2a1ac29a69fd23741afd3e54d912..d62d3ba7dee23e06f5228b3fa5d6123479e58f11 100755 (executable)
@@ -33,14 +33,24 @@ Paths to the blends top directories, containing tasks directories are
 specified in ~/.blends-inject.cfg file, e.g.::
 
  [debian-med]
- path = /home/yoh/deb/debian-med/
+ path = ~/deb/debian-med/
 
  [debian-science]
- path = /home/yoh/deb/debian-science/
-
+ path = ~/deb/debian-science/
 
 Definition of the fields for task files by default are looked up
-within debian/blends, or files provided in the command line.
+within debian/blends, or files provided in the command line.  Also for "-a"
+mode of operation you should define list of globs to match your debian/blends
+files::
+
+ [paths]
+ all=~/deb/gits/pkg-exppsy/neurodebian/future/blends/*
+     ~/deb/gits/*/debian/blends
+     ~/deb/gits/pkg-exppsy/*/debian/blends
+ # Python regular expression on which files to skip
+ # Default is listed below
+ #skip=.*[~#]$
+
 
 Format of debian/blends
 -----------------------
@@ -104,7 +114,7 @@ Remove: python-brian-doc
 """
 
 
-import re, os, sys, tempfile
+import re, os, sys, tempfile, glob
 from os.path import join, exists, expanduser, dirname, basename
 
 from ConfigParser import ConfigParser
@@ -125,7 +135,7 @@ def open(f, *args):
 
 __author__ = 'Yaroslav Halchenko'
 __prog__ = os.path.basename(sys.argv[0])
-__version__ = '0.0.4'
+__version__ = '0.0.7'
 __copyright__ = 'Copyright (c) 2010 Yaroslav Halchenko'
 __license__ = 'GPL'
 
@@ -185,7 +195,9 @@ def parse_debian_blends(f='debian/blends'):
             pkg = deepcopy(prev_pkg)
             for k_ in PKG_FIELDS:   # prune older depends
                 pkg.pop(k_, None)
-        pkg['Pkg-Name'] = pkg[k] = bname
+        pkg['Pkg-Name'] = pkg[k] = bname.lower()
+        if sname is not None:
+            sname = sname.lower()
         pkg['Pkg-Source'] = sname
         pkgs.append(pkg)
         pkg.tasks = dict( (t.strip(), deb822.Deb822Dict()) for t in tasks )
@@ -204,11 +216,11 @@ def parse_debian_blends(f='debian/blends'):
             if format_clean:
                 format_ = format_[:-6]
         elif kl == 'tasks':
-            tasks = v.split(',')
+            tasks = [x.strip() for x in v.split(',')]
             newtasks = pkg is not None      # either we need to provide tune-ups
                                             # for current package
         elif kl in PKG_FIELDS: # new package
-            if source is None:
+            if source is None and not format_ in ['extended']:
                 source = v
             pkg = new_pkg(pkg, v, source, tasks)
             newtasks = False
@@ -220,7 +232,7 @@ def parse_debian_blends(f='debian/blends'):
                                        # TODO: just deduce source from DebianMaterials
                                pkg = new_pkg(pkg, source, source, tasks)
                                # Since only source is available, it should be only Suggest:-ed
-                               pkg['Suggests'] = source
+                               pkg['Suggests'] = source.lower()
                                newtasks = False
 
             if newtasks:
@@ -254,7 +266,9 @@ def expand_pkgs(pkgs, topdir='.'):
                          ('Pkg-Description',
                           lambda: debianm.get_description(pkg['Pkg-Name'])),
                          ('Responsible', debianm.get_responsible),
-                         ('Homepage', lambda: debianm.source.get('Homepage', None))):
+                         ('Homepage', lambda: debianm.source.get('Homepage', None)),
+                         ('Pkg-source', lambda: debianm.source.get('Source', None)),
+                         ):
                 if pkg.get(k, None):
                     continue
                 v = m()
@@ -345,7 +359,7 @@ def inject_tasks(tasks, config):
     for task, pkgs in tasks.iteritems():
         verbose(2, "Task %s with %d packages" % (task, len(pkgs)))
         blend, puretask = task.split('/')
-        taskfile = join(config.get(blend, 'path'), 'tasks', puretask)
+        taskfile = expanduser(join(config.get(blend, 'path'), 'tasks', puretask))
 
         # Load the file
         stats = dict(Added=[], Modified=[])
@@ -368,11 +382,13 @@ def inject_tasks(tasks, config):
             entries = open(taskfile).readlines()
             known = False
             # We need to search by name and by source
-            # We need to search for every possible type of dependecy
-            regexp = re.compile('^ *(%s) *: *(%s) *$' %
-                                ('|'.join(PKG_FIELDS),
-                                '|'.join((pkg.name, pkg.source))),
-                                re.I)
+            # We need to search for every possible type of dependency
+            regexp_str = '^ *(%s) *: *(%s) *$' \
+                         % ('|'.join(PKG_FIELDS),
+                            '|'.join((pkg.name, pkg.source)).replace('+', '\+'))
+            verbose(4, "Searching for presence in %s using regexp: '%s'"
+                    % (taskfile, regexp_str))
+            regexp = re.compile(regexp_str, re.I)
             for istart, e in enumerate(entries):
                 if regexp.search(e):
                     verbose(4, "Found %s in position %i: %s" %
@@ -487,7 +503,9 @@ class DebianMaterials(object):
             if v.get('Source', None):
                 self._source = v
             else:
-                self._binaries[v['Package']] = v
+                # Since it might be hash-commented out
+                if 'Package' in v:
+                    self._binaries[v['Package']] = v
 
     def get_license(self, package=None, first_only=True):
         """Return a license(s). Parsed out from debian/copyright if it is
@@ -593,6 +611,20 @@ def print_wnpp(pkgs, config, wnpp_type="ITP"):
         print "Subject: %s\n\n%s" % (subject, body)
 
 
+def is_template(p):
+    """Helper to return true if pkg definition looks like a template
+       and should not be processed
+    """
+    # We might want to skip some which define a skeleton
+    # (no source/homepage/etc although fields are there)
+    for f in ['vcs-browser', 'pkg-url', 'pkg-description',
+              'published-Title', 'pkg-name', 'homepage',
+              'author']:
+        if f in p and p[f] != "":
+            return False
+    return True
+
+
 def main():
 
     p = OptionParser(
@@ -626,6 +658,11 @@ def main():
                dest="wnpp_mode", default=None,
                help="Operate in WNPP mode: dumps cut-paste-able entry for WNPP bugreport"))
 
+    p.add_option(
+        Option("-a", action="store_true",
+               dest="all_mode", default=False,
+               help="Process all files listed in paths.all"))
+
 
     (options, infiles) = p.parse_args()
     global verbosity; verbosity = options.verbosity
@@ -633,18 +670,30 @@ def main():
        if options.wnpp and options.wnpp_mode is None:
             options.wnpp_mode = 'ITP'
 
+    # Load configuration
+    config = ConfigParser(defaults={'skip': '.*[~#]$'})
+    config.read(options.config_file)
+
+    if options.all_mode:
+        if len(infiles):
+            raise ValueError("Do not specify any files in -a mode.  Use configuration file, section paths, option all")
+        globs = config.get('paths', 'all', None).split()
+        infiles = reduce(list.__add__, (glob.glob(expanduser(f)) for f in globs))
+        verbose(1, "Found %d files in specified paths" % len(infiles))
+
     if not len(infiles):
         infiles = [join(options.topdir or './', 'debian/blends')]     #  default one
 
-    # Load configuration
-    config = ConfigParser()
-    config.read(options.config_file)
+    skip_re = re.compile(config.get('paths', 'skip', None))
 
     for blends_file in infiles:
         verbose(1, "Processing %s" % blends_file)
         if not exists(blends_file):
             error("Cannot find a file %s.  Either provide a file or specify top "
                   "debian directory with -d." % blends_file, 1)
+        if skip_re.match(blends_file):
+            verbose(2, "W: Skipped since matches paths.skip regexp")
+            continue
         pkgs = parse_debian_blends(blends_file)
         if options.topdir is None:
             if dirname(blends_file).endswith('/debian'):
@@ -655,6 +704,11 @@ def main():
             topdir = options.topdir
 
                expand_pkgs(pkgs, topdir=topdir)
+
+        pkgs = [p for p in pkgs if not is_template(p)]
+        if not len(pkgs):
+            verbose(2, "W: Skipping since seems to contain templates only")
+            continue
         if options.wnpp_mode is not None:
                    print_wnpp(pkgs, config, options.wnpp_mode)
         else: