Bug #275217 - Part 2 - Move changelog stuff stuff out of depgraph.
authorZac Medico <zmedico@gentoo.org>
Tue, 23 Jun 2009 20:44:49 +0000 (20:44 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 23 Jun 2009 20:44:49 +0000 (20:44 -0000)
Thanks to Sebastian Mingramm (few) <s.mingramm@gmx.de> for this patch.

svn path=/main/trunk/; revision=13677

pym/_emerge/changelog.py [new file with mode: 0644]
pym/_emerge/depgraph.py

diff --git a/pym/_emerge/changelog.py b/pym/_emerge/changelog.py
new file mode 100644 (file)
index 0000000..8084ecb
--- /dev/null
@@ -0,0 +1,62 @@
+import os
+import re
+
+try:
+       import portage
+except ImportError:
+       from os import path as osp
+       import sys
+       sys.path.insert(0, osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "pym"))
+       import portage
+
+def calc_changelog(ebuildpath,current,next):
+       if ebuildpath == None or not os.path.exists(ebuildpath):
+               return []
+       current = '-'.join(portage.catpkgsplit(current)[1:])
+       if current.endswith('-r0'):
+               current = current[:-3]
+       next = '-'.join(portage.catpkgsplit(next)[1:])
+       if next.endswith('-r0'):
+               next = next[:-3]
+       changelogpath = os.path.join(os.path.split(ebuildpath)[0],'ChangeLog')
+       try:
+               changelog = open(changelogpath).read()
+       except SystemExit, e:
+               raise # Needed else can't exit
+       except:
+               return []
+       divisions = _find_changelog_tags(changelog)
+       #print 'XX from',current,'to',next
+       #for div,text in divisions: print 'XX',div
+       # skip entries for all revisions above the one we are about to emerge
+       for i in range(len(divisions)):
+               if divisions[i][0]==next:
+                       divisions = divisions[i:]
+                       break
+       # find out how many entries we are going to display
+       for i in range(len(divisions)):
+               if divisions[i][0]==current:
+                       divisions = divisions[:i]
+                       break
+       else:
+           # couldnt find the current revision in the list. display nothing
+               return []
+       return divisions
+
+def _find_changelog_tags(changelog):
+       divs = []
+       release = None
+       while 1:
+               match = re.search(r'^\*\ ?([-a-zA-Z0-9_.+]*)(?:\ .*)?\n',changelog,re.M)
+               if match is None:
+                       if release is not None:
+                               divs.append((release,changelog))
+                       return divs
+               if release is not None:
+                       divs.append((release,changelog[:match.start()]))
+               changelog = changelog[match.end():]
+               release = match.group(1)
+               if release.endswith('.ebuild'):
+                       release = release[:-7]
+               if release.endswith('-r0'):
+                       release = release[:-3]
index 29c9ed9c6239061dad5e9c63003428d2dce87050..cf31e51017234408fca4c13d3bd807180761afb3 100644 (file)
@@ -24,6 +24,7 @@ from _emerge.AtomArg import AtomArg
 from _emerge.Blocker import Blocker
 from _emerge.BlockerCache import BlockerCache
 from _emerge.BlockerDepPriority import BlockerDepPriority
+from _emerge.changelog import calc_changelog
 from _emerge.countdown import countdown
 from _emerge.create_world_atom import create_world_atom
 from _emerge.Dependency import Dependency
@@ -3767,7 +3768,7 @@ class depgraph(object):
                                        if "--changelog" in self.myopts:
                                                inst_matches = vardb.match(pkg.slot_atom)
                                                if inst_matches:
-                                                       changelogs.extend(self._calc_changelog(
+                                                       changelogs.extend(calc_changelog(
                                                                portdb.findname(pkg_key),
                                                                inst_matches[0], pkg_key))
                                else:
@@ -4262,58 +4263,6 @@ class depgraph(object):
                        show_mask_docs()
                        print
 
-       def _calc_changelog(self,ebuildpath,current,next):
-               if ebuildpath == None or not os.path.exists(ebuildpath):
-                       return []
-               current = '-'.join(portage.catpkgsplit(current)[1:])
-               if current.endswith('-r0'):
-                       current = current[:-3]
-               next = '-'.join(portage.catpkgsplit(next)[1:])
-               if next.endswith('-r0'):
-                       next = next[:-3]
-               changelogpath = os.path.join(os.path.split(ebuildpath)[0],'ChangeLog')
-               try:
-                       changelog = open(changelogpath).read()
-               except SystemExit, e:
-                       raise # Needed else can't exit
-               except:
-                       return []
-               divisions = self.find_changelog_tags(changelog)
-               #print 'XX from',current,'to',next
-               #for div,text in divisions: print 'XX',div
-               # skip entries for all revisions above the one we are about to emerge
-               for i in range(len(divisions)):
-                       if divisions[i][0]==next:
-                               divisions = divisions[i:]
-                               break
-               # find out how many entries we are going to display
-               for i in range(len(divisions)):
-                       if divisions[i][0]==current:
-                               divisions = divisions[:i]
-                               break
-               else:
-                   # couldnt find the current revision in the list. display nothing
-                       return []
-               return divisions
-
-       def _find_changelog_tags(self,changelog):
-               divs = []
-               release = None
-               while 1:
-                       match = re.search(r'^\*\ ?([-a-zA-Z0-9_.+]*)(?:\ .*)?\n',changelog,re.M)
-                       if match is None:
-                               if release is not None:
-                                       divs.append((release,changelog))
-                               return divs
-                       if release is not None:
-                               divs.append((release,changelog[:match.start()]))
-                       changelog = changelog[match.end():]
-                       release = match.group(1)
-                       if release.endswith('.ebuild'):
-                               release = release[:-7]
-                       if release.endswith('-r0'):
-                               release = release[:-3]
-
        def saveNomergeFavorites(self):
                """Find atoms in favorites that are not in the mergelist and add them
                to the world file if necessary."""