/[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 2936 by ovitters, Sun Feb 12 12:23:46 2012 UTC revision 2944 by ovitters, Tue Feb 14 10:38:56 2012 UTC
# Line 9  import urllib2 Line 9  import urllib2
9  import urlparse  import urlparse
10  import argparse  import argparse
11  import errno  import errno
12    import tempfile
13    import shutil
14  from sgmllib import SGMLParser  from sgmllib import SGMLParser
15    
16  MEDIA="Core Release Source"  MEDIA="Core Release Source"
# Line 47  class Patch(object): Line 49  class Patch(object):
49          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)
50    
51      def add_dep3(self):      def add_dep3(self):
52          pass          if self.dep3['valid']:
53                return False
54    
55            new_headers = (
56                ('Author', self.svn_author),
57                ('Subject', ''),
58                ('Applied-Upstream', ''),
59                ('Forwarded', ''),
60                ('Bug', ''),
61            )
62    
63            with tempfile.NamedTemporaryFile(dir=os.path.dirname(self.path), delete=False) as fdst:
64                with open(self.path, "r") as fsrc:
65                    # Start with any existing DEP3 headers
66                    for i in range(self.dep3['last_nr']):
67                        fdst.write(fsrc.read())
68    
69                    # After that add the DEP3 headers
70                    add_line = False
71                    for header, data in new_headers:
72                        if header in self.dep3['headers']:
73                            continue
74    
75                        # XXX - wrap this at 80 chars
76                        add_line = True
77                        print >>fdst, "%s: %s" % (header, data)
78    
79                    if add_line: print >>fdst, ""
80                    # Now copy any other data and the patch
81                    shutil.copyfileobj(fsrc, fdst)
82    
83                fdst.flush()
84                os.rename(fdst.name, self.path)
85    
86      #Author: fwang      #Author: fwang
87      #Subject: Build fix: Fix glib header inclusion      #Subject: Build fix: Fix glib header inclusion
88      #Applied-Upstream: commit:30602      #Applied-Upstream: commit:30602
# Line 57  class Patch(object): Line 92  class Patch(object):
92      def _read_dep3(self):      def _read_dep3(self):
93          """This will also parse git headers"""          """This will also parse git headers"""
94          dep3 = {}          dep3 = {}
95            headers = {}
96    
97          last_header = None          last_header = None
98            last_nr = 0
99            nr = 0
100          try:          try:
101              with open(self.path, "r") as f:              with open(self.path, "r") as f:
102                  for line in line_input(f):                  for line in line_input(f):
103                      # Check for start of real patch                      nr += 1
104                        # stop trying to parse when real patch begins
105                      if line == '---':                      if line == '---':
106                          break                          break
107    
108                      r = self.re_dep3.match(line)                      r = self.re_dep3.match(line)
109                      if r:                      if r:
110                          info = r.groupdict()                          info = r.groupdict()
111                          dep3[info['header']] = info['data']                          headers[info['header']] = info['data']
112                          last_header = info['header']                          last_header = info['header']
113                            last_nr = nr
114                          continue                          continue
115    
116                      r = self.re_dep3_cont.match(line)                      r = self.re_dep3_cont.match(line)
117                      if r:                      if r:
118                          info = r.groupdict()                          info = r.groupdict()
119                          if last_header:                          if last_header:
120                              dep3[last_header] = " ".join((dep3[last_header], info['data']))                              headers[last_header] = " ".join((headers[last_header], info['data']))
121                                last_nr = nr
122                          continue                          continue
123    
124                      last_header = None                      last_header = None
125          except IOError:          except IOError:
126              pass              pass
127    
128            dep3['valid'] = \
129                (('Description' in headers and headers['Description'].strip() != '')
130                    or ('Subject' in headers and headers['Subject'].strip() != '')) \
131                and (('Origin' in headers and headers['Origin'].strip() != '') \
132                    or ('Author' in headers and headers['Author'].strip() != '') \
133                    or ('From' in headers and headers['From'].strip() != ''))
134            dep3['last_nr'] = last_nr
135            dep3['headers'] = headers
136    
137          self._dep3 = dep3          self._dep3 = dep3
138    
139      @property      @property
# Line 92  class Patch(object): Line 143  class Patch(object):
143    
144          return self._dep3          return self._dep3
145    
146        @property
147        def svn_author(self):
148            if not hasattr(self, '_svn_author'):
149                p = subprocess.Popen(['svn', 'log', '-q', "--", self.path], stdout=subprocess.PIPE, close_fds=True)
150                contents = p.stdout.read().strip("\n").splitlines()
151                ecode = p.wait()
152                if ecode == 0:
153                    for line in contents:
154                        if ' | ' not in line:
155                            continue
156    
157                        fields = line.split(' | ')
158                        if len(fields) >= 3:
159                            self._svn_author = fields[1]
160    
161            return self._svn_author
162    
163  def get_upstream_names():  def get_upstream_names():
164      urlopen = urllib2.build_opener()      urlopen = urllib2.build_opener()
# Line 180  def cmd_patches(options, parser): Line 247  def cmd_patches(options, parser):
247                  if '.patch' in filename or '.diff' in filename:                  if '.patch' in filename or '.diff' in filename:
248                      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)
249                      print "\t".join((module, srpm, str(p)))                      print "\t".join((module, srpm, str(p)))
250                      if p.dep3:                      if p.dep3['headers']:
251                          pprint.pprint(p.dep3)                          pprint.pprint(p.dep3['headers'])
252                            if p.dep3['valid']:
253                                print "VALID"
254    
255    def cmd_dep3(options, parser):
256        p = Patch(options.patch)
257        p.add_dep3()
258    
259  def main():  def main():
260      description = """Mageia GNOME commands."""      description = """Mageia GNOME commands."""
# Line 203  def main(): Line 276  def main():
276    
277      subparser = subparsers.add_parser('patches', help='list all GNOME patches')      subparser = subparsers.add_parser('patches', help='list all GNOME patches')
278      subparser.add_argument("-p", "--path", action="store_true", dest="path",      subparser.add_argument("-p", "--path", action="store_true", dest="path",
279                                         help="Full path to patch")                                         help="Show full path to patch")
280      subparser.set_defaults(      subparser.set_defaults(
281          func=cmd_patches, path=False          func=cmd_patches, path=False
282      )      )
283    
284        subparser = subparsers.add_parser('dep3', help='Add dep3 headers')
285        subparser.add_argument("patch", help="Patch")
286        subparser.set_defaults(
287            func=cmd_dep3, path=False
288        )
289    
290      if len(sys.argv) == 1:      if len(sys.argv) == 1:
291          parser.print_help()          parser.print_help()

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

  ViewVC Help
Powered by ViewVC 1.1.30