/[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 2944 by ovitters, Tue Feb 14 10:38:56 2012 UTC revision 3045 by ovitters, Fri Feb 24 12:26:02 2012 UTC
# Line 11  import argparse Line 11  import argparse
11  import errno  import errno
12  import tempfile  import tempfile
13  import shutil  import shutil
14    import rpm
15  from sgmllib import SGMLParser  from sgmllib import SGMLParser
16    
17  MEDIA="Core Release Source"  MEDIA="Core Release Source"
18  URL="http://download.gnome.org/sources/"  URL="http://download.gnome.org/sources/"
19  PKGROOT='~/pkgs'  PKGROOT='~/pkgs'
20    
21    re_version = re.compile(r'([-.]|\d+|[^-.\d]+)')
22    
23    def version_cmp(a, b):
24        """Compares two versions
25    
26        Returns
27          -1 if a < b
28          0  if a == b
29          1  if a > b
30        """
31    
32        return rpm.labelCompare(('1', a, '1'), ('1', b, '1'))
33    
34    def get_latest_version(versions, max_version=None):
35        """Gets the latest version number
36    
37        if max_version is specified, gets the latest version number before
38        max_version"""
39        latest = None
40        for version in versions:
41            if ( latest is None or version_cmp(version, latest) > 0 ) \
42               and ( max_version is None or version_cmp(version, max_version) < 0 ):
43                latest = version
44        return latest
45    
46  def line_input (file):  def line_input (file):
47      for line in file:      for line in file:
48          if line[-1] == '\n':          if line[-1] == '\n':
# Line 24  def line_input (file): Line 50  def line_input (file):
50          else:          else:
51              yield line              yield line
52    
53    def call_editor(filename):
54        """Return a sequence of possible editor binaries for the current platform"""
55    
56        editors = []
57    
58        for varname in 'VISUAL', 'EDITOR':
59            if varname in os.environ:
60                editors.append(os.environ[varname])
61    
62        editors.extend(('/usr/bin/editor', 'vi', 'pico', 'nano', 'joe'))
63    
64        for editor in editors:
65            try:
66                ret = subprocess.call([editor, filename])
67            except OSError, e:
68                if e.errno == 2:
69                    continue
70                raise
71    
72            if ret == 127:
73                continue
74    
75            return True
76    
77  class urllister(SGMLParser):  class urllister(SGMLParser):
78      def reset(self):      def reset(self):
79          SGMLParser.reset(self)          SGMLParser.reset(self)
# Line 34  class urllister(SGMLParser): Line 84  class urllister(SGMLParser):
84          if href:          if href:
85              self.urls.extend(href)              self.urls.extend(href)
86    
87    class SpecFile(object):
88        re_update_version = re.compile(r'^(?P<pre>Version:\s*)(?P<version>.+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE)
89        re_update_release = re.compile(r'^(?P<pre>Release:\s*)(?P<release>%mkrel \d+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE)
90    
91        def __init__(self, path):
92            self.path = path
93            self.cwd = os.path.dirname(path)
94    
95        @property
96        def version(self):
97            return subprocess.check_output(["rpm", "--specfile", self.path, "--queryformat", "%{VERSION}\n"]).splitlines()[0]
98    
99        def update(self, version):
100            """Update specfile (increase version)"""
101            cur_version = self.version
102    
103            compare = version_cmp(version, cur_version)
104    
105            if compare == 0:
106                print >>sys.stderr, "ERROR: Already at version %s!" % (cur_version)
107                return False
108    
109            if compare != 1:
110                print >>sys.stderr, "ERROR: Version %s is older than current version %s!" % (version, cur_version)
111                return False
112    
113            # XXX - os.path.join is hackish
114            if subprocess.check_output(["svn", "diff", os.path.join(self.path, '..')]) != '':
115                print >>sys.stderr, "ERROR: Package has uncommitted changes!"
116                return False
117    
118            with open(self.path, "rw") as f:
119                data = f.read()
120    
121                if data.count("%mkrel") != 1:
122                    print >>sys.stderr, "ERROR: Multiple %mkrel found; don't know what to do!"
123                    return False
124    
125                data, nr = self.re_update_version.subn(r'\g<pre>%s\g<post>' % version, data, 1)
126                if nr != 1:
127                    print >>sys.stderr, "ERROR: Could not increase version!"
128                    return False
129    
130                data, nr = self.re_update_release.subn(r'\g<pre>%mkrel 1\g<post>', data, 1)
131                if nr != 1:
132                    print >>sys.stderr, "ERROR: Could not reset release!"
133                    return False
134    
135                # Overwrite file with new version number
136                write_file(self.path, data)
137    
138    
139            # Verify that RPM also agrees that version number has changed
140            if self.version != version:
141                print "ERROR: Increased version to %s, but RPM doesn't agree!?!" % version
142                return False
143    
144            try:
145                # Download new tarball
146                subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd)
147                # Check patches still apply
148                subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd)
149            except subprocess.CalledProcessError:
150                return False
151    
152            return True
153    
154  class Patch(object):  class Patch(object):
155      """Do things with patches"""      """Do things with patches"""
156    
# Line 49  class Patch(object): Line 166  class Patch(object):
166          return self.path if self.show_path else os.path.basename(self.path)          return self.path if self.show_path else os.path.basename(self.path)
167    
168      def add_dep3(self):      def add_dep3(self):
169            """Add DEP-3 headers to a patch file"""
170          if self.dep3['valid']:          if self.dep3['valid']:
171              return False              return False
172    
# Line 74  class Patch(object): Line 192  class Patch(object):
192    
193                      # XXX - wrap this at 80 chars                      # XXX - wrap this at 80 chars
194                      add_line = True                      add_line = True
195                      print >>fdst, "%s: %s" % (header, data)                      print >>fdst, "%s: %s" % (header, "" if data is None else data)
196    
197                  if add_line: print >>fdst, ""                  if add_line: print >>fdst, ""
198                  # Now copy any other data and the patch                  # Now copy any other data and the patch
# Line 83  class Patch(object): Line 201  class Patch(object):
201              fdst.flush()              fdst.flush()
202              os.rename(fdst.name, self.path)              os.rename(fdst.name, self.path)
203    
204            call_editor(self.path)
205    
206      #Author: fwang      #Author: fwang
207      #Subject: Build fix: Fix glib header inclusion      #Subject: Build fix: Fix glib header inclusion
208      #Applied-Upstream: commit:30602      #Applied-Upstream: commit:30602
# Line 90  class Patch(object): Line 210  class Patch(object):
210      #Bug: http://bugzilla.abisource.com/show_bug.cgi?id=13247      #Bug: http://bugzilla.abisource.com/show_bug.cgi?id=13247
211    
212      def _read_dep3(self):      def _read_dep3(self):
213          """This will also parse git headers"""          """Read DEP-3 headers from an existing patch file
214    
215            This will also parse git headers"""
216          dep3 = {}          dep3 = {}
217          headers = {}          headers = {}
218    
# Line 108  class Patch(object): Line 230  class Patch(object):
230                      r = self.re_dep3.match(line)                      r = self.re_dep3.match(line)
231                      if r:                      if r:
232                          info = r.groupdict()                          info = r.groupdict()
233    
234                            # Avoid matching URLS
235                            if info['data'].startswith('//') and info['header'].lower () == info['header']:
236                                continue
237    
238                          headers[info['header']] = info['data']                          headers[info['header']] = info['data']
239                          last_header = info['header']                          last_header = info['header']
240                          last_nr = nr                          last_nr = nr
# Line 158  class Patch(object): Line 285  class Patch(object):
285                      if len(fields) >= 3:                      if len(fields) >= 3:
286                          self._svn_author = fields[1]                          self._svn_author = fields[1]
287    
288            if not hasattr(self, '_svn_author'):
289                return None
290    
291          return self._svn_author          return self._svn_author
292    
293  def get_upstream_names():  def get_upstream_names():
# Line 212  def get_downstream_names(): Line 342  def get_downstream_names():
342    
343      return TARBALLS, FILES      return TARBALLS, FILES
344    
345    
346    def write_file(path, data):
347        with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst:
348            fdst.write(data)
349            fdst.flush()
350            os.rename(fdst.name, path)
351    
352  def cmd_co(options, parser):  def cmd_co(options, parser):
353      upstream = get_upstream_names()      upstream = get_upstream_names()
354      downstream, downstream_files = get_downstream_names()      downstream, downstream_files = get_downstream_names()
# Line 245  def cmd_patches(options, parser): Line 382  def cmd_patches(options, parser):
382          for srpm in downstream[module]:          for srpm in downstream[module]:
383              for filename in downstream_files[srpm]:              for filename in downstream_files[srpm]:
384                  if '.patch' in filename or '.diff' in filename:                  if '.patch' in filename or '.diff' in filename:
385    
386                      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)
387                      print "\t".join((module, srpm, str(p)))                      valid = ""
388                        forwarded = ""
389                      if p.dep3['headers']:                      if p.dep3['headers']:
390                          pprint.pprint(p.dep3['headers'])                          forwarded = p.dep3['headers'].get('Forwarded', "no")
391                          if p.dep3['valid']:                          if p.dep3['valid']:
392                              print "VALID"                              valid="VALID"
393                        print "\t".join((module, srpm, str(p), forwarded, valid))
394    
395  def cmd_dep3(options, parser):  def cmd_dep3(options, parser):
396      p = Patch(options.patch)      p = Patch(options.patch)
397      p.add_dep3()      p.add_dep3()
398    
399    def cmd_package_new_version(options, parser):
400        package = options.package
401    
402        root = os.path.expanduser(PKGROOT)
403        cwd = os.path.join(root, package)
404    
405        try:
406            subprocess.check_call(['mgarepo', 'co', package], cwd=root)
407        except subprocess.CalledProcessError:
408            sys.exit(1)
409        s = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package))
410        print "%s => %s" % (s.version, options.version)
411        if not s.update(options.version):
412            sys.exit(1)
413    
414        if options.submit:
415            try:
416                # checkin changes
417                subprocess.check_call(['mgarepo', 'ci', '-m', 'new version'], cwd=cwd)
418                # and submit
419                subprocess.check_call(['mgarepo', 'submit'], cwd=cwd)
420            except subprocess.CalledProcessError:
421                sys.exit(1)
422    
423    
424  def main():  def main():
425      description = """Mageia GNOME commands."""      description = """Mageia GNOME commands."""
426      epilog="""Report bugs to Olav Vitters"""      epilog="""Report bugs to Olav Vitters"""
# Line 287  def main(): Line 452  def main():
452          func=cmd_dep3, path=False          func=cmd_dep3, path=False
453      )      )
454    
455        subparser = subparsers.add_parser('increase', help='Increase version number')
456        subparser.add_argument("package", help="Package name")
457        subparser.add_argument("version", help="Version number")
458        subparser.add_argument("-s", "--submit", action="store_true", dest="submit",
459                                           help="Commit changes and submit")
460        subparser.set_defaults(
461            func=cmd_package_new_version, submit=False
462        )
463    
464      if len(sys.argv) == 1:      if len(sys.argv) == 1:
465          parser.print_help()          parser.print_help()
466          sys.exit(2)          sys.exit(2)

Legend:
Removed from v.2944  
changed lines
  Added in v.3045

  ViewVC Help
Powered by ViewVC 1.1.30