/[soft]/mga-gnome/trunk/mga-gnome
ViewVC logotype

Diff of /mga-gnome/trunk/mga-gnome

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2955 by ovitters, Wed Feb 15 15:11:17 2012 UTC revision 3012 by ovitters, Wed Feb 22 16:06:51 2012 UTC
# Line 17  MEDIA="Core Release Source" Line 17  MEDIA="Core Release Source"
17  URL="http://download.gnome.org/sources/"  URL="http://download.gnome.org/sources/"
18  PKGROOT='~/pkgs'  PKGROOT='~/pkgs'
19    
20    re_version = re.compile(r'([-.]|\d+|[^-.\d]+)')
21    
22    def version_cmp(a, b):
23        """Compares two versions
24    
25        Returns
26          -1 if a < b
27          0  if a == b
28          1  if a > b
29    
30        Logic from Bugzilla::Install::Util::vers_cmp"""
31        A = re_version.findall(a.lstrip('0'))
32        B = re_version.findall(b.lstrip('0'))
33    
34        while A and B:
35            a = A.pop(0)
36            b = B.pop(0)
37    
38            if a == b:
39                continue
40            elif a == '-':
41                return -1
42            elif b == '-':
43                return 1
44            elif a == '.':
45                return -1
46            elif b == '.':
47                return 1
48            elif a.isdigit() and b.isdigit():
49                c = cmp(a, b) if (a.startswith('0') or b.startswith('0')) else cmp(int(a, 10), int(b, 10))
50                if c:
51                    return c
52            else:
53                c = cmp(a.upper(), b.upper())
54                if c:
55                    return c
56    
57        return cmp(len(A), len(B))
58    
59    def get_latest_version(versions, max_version=None):
60        """Gets the latest version number
61    
62        if max_version is specified, gets the latest version number before
63        max_version"""
64        latest = None
65        for version in versions:
66            if ( latest is None or version_cmp(version, latest) > 0 ) \
67               and ( max_version is None or version_cmp(version, max_version) < 0 ):
68                latest = version
69        return latest
70    
71  def line_input (file):  def line_input (file):
72      for line in file:      for line in file:
73          if line[-1] == '\n':          if line[-1] == '\n':
# Line 58  class urllister(SGMLParser): Line 109  class urllister(SGMLParser):
109          if href:          if href:
110              self.urls.extend(href)              self.urls.extend(href)
111    
112    class SpecFile(object):
113        re_update_version = re.compile(r'^(?P<pre>Version:\s*)(?P<version>.+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE)
114        re_update_release = re.compile(r'^(?P<pre>Release:\s*)(?P<release>%mkrel \d+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE)
115    
116        def __init__(self, path):
117            self.path = path
118            self.cwd = os.path.dirname(path)
119    
120        @property
121        def version(self):
122            return subprocess.check_output(["rpm", "--specfile", self.path, "--queryformat", "%{VERSION}\n"]).splitlines()[0]
123        def update(self, version):
124            """Update specfile (increase version)"""
125            cur_version = self.version
126    
127            if version_cmp(version, cur_version) != 1:
128                print >>sys.stderr, "ERROR: Version %s is older than current version %s!" % (version, cur_version)
129                return False
130    
131            with open(self.path, "rw") as f:
132                data = f.read()
133    
134                if data.count("%mkrel") != 1:
135                    print "WARNING: Multiple %mkrel found; don't know what to do!"
136                    return False
137    
138                data, nr = self.re_update_version.subn(r'\g<pre>%s\g<post>' % version, data, 1)
139                if nr != 1:
140                    print "WARNING: Could not increase version!"
141                    return False
142    
143                data, nr = self.re_update_release.subn(r'\g<pre>%mkrel 1\g<post>', data, 1)
144                if nr != 1:
145                    print "WARNING: Could not reset release!"
146                    return False
147    
148                # Overwrite file with new version number
149                write_file(self.path, data)
150    
151    
152            # Check RPM also agrees that version number has increased
153            if self.version != version:
154                print "ERROR: Increased version to %s, but RPM doesn't agree!?!" % version
155                return False
156    
157            # Download new tarball
158            subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd)
159            # Check patches still apply
160            subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd)
161    
162            return True
163    
164  class Patch(object):  class Patch(object):
165      """Do things with patches"""      """Do things with patches"""
166    
# Line 137  class Patch(object): Line 240  class Patch(object):
240                      r = self.re_dep3.match(line)                      r = self.re_dep3.match(line)
241                      if r:                      if r:
242                          info = r.groupdict()                          info = r.groupdict()
243    
244                            # Avoid matching URLS
245                            if info['data'].startswith('//') and info['header'].lower () == info['header']:
246                                continue
247    
248                          headers[info['header']] = info['data']                          headers[info['header']] = info['data']
249                          last_header = info['header']                          last_header = info['header']
250                          last_nr = nr                          last_nr = nr
# Line 244  def get_downstream_names(): Line 352  def get_downstream_names():
352    
353      return TARBALLS, FILES      return TARBALLS, FILES
354    
355    
356    def write_file(path, data):
357        with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst:
358            fdst.write(data)
359            fdst.flush()
360            os.rename(fdst.name, path)
361    
362  def cmd_co(options, parser):  def cmd_co(options, parser):
363      upstream = get_upstream_names()      upstream = get_upstream_names()
364      downstream, downstream_files = get_downstream_names()      downstream, downstream_files = get_downstream_names()
# Line 277  def cmd_patches(options, parser): Line 392  def cmd_patches(options, parser):
392          for srpm in downstream[module]:          for srpm in downstream[module]:
393              for filename in downstream_files[srpm]:              for filename in downstream_files[srpm]:
394                  if '.patch' in filename or '.diff' in filename:                  if '.patch' in filename or '.diff' in filename:
395    
396                      p = Patch(os.path.join(path, srpm, "SOURCES", filename), show_path=options.path)                      p = Patch(os.path.join(path, srpm, "SOURCES", filename), show_path=options.path)
397                      print "\t".join((module, srpm, str(p)))                      valid = ""
398                        forwarded = ""
399                      if p.dep3['headers']:                      if p.dep3['headers']:
400                          pprint.pprint(p.dep3['headers'])                          forwarded = p.dep3['headers'].get('Forwarded', "no")
401                          if p.dep3['valid']:                          if p.dep3['valid']:
402                              print "VALID"                              valid="VALID"
403                        print "\t".join((module, srpm, str(p), forwarded, valid))
404    
405  def cmd_dep3(options, parser):  def cmd_dep3(options, parser):
406      p = Patch(options.patch)      p = Patch(options.patch)
407      p.add_dep3()      p.add_dep3()
408    
409    def cmd_package_new_version(options, parser):
410        cwd = os.path.expanduser(PKGROOT)
411        package = options.package
412    
413        subprocess.call(['mgarepo', 'co', package], cwd=cwd)
414        s = SpecFile(os.path.join(cwd, package, "SPECS", "%s.spec" % package))
415        print s.version
416        if not s.update(options.version):
417            sys.exit(1)
418    
419    
420  def main():  def main():
421      description = """Mageia GNOME commands."""      description = """Mageia GNOME commands."""
422      epilog="""Report bugs to Olav Vitters"""      epilog="""Report bugs to Olav Vitters"""
# Line 319  def main(): Line 448  def main():
448          func=cmd_dep3, path=False          func=cmd_dep3, path=False
449      )      )
450    
451        subparser = subparsers.add_parser('increase', help='Increase version number')
452        subparser.add_argument("package", help="Package name")
453        subparser.add_argument("version", help="Version number")
454        subparser.set_defaults(
455            func=cmd_package_new_version, path=False
456        )
457    
458      if len(sys.argv) == 1:      if len(sys.argv) == 1:
459          parser.print_help()          parser.print_help()
460          sys.exit(2)          sys.exit(2)

Legend:
Removed from v.2955  
changed lines
  Added in v.3012

  ViewVC Help
Powered by ViewVC 1.1.30