From 67212a8d81a3694ee075f75f5041542f1655dab1 Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Sun, 30 Jun 2013 19:05:00 -0500 Subject: minor cleanups, added imports, --HG-- extra : rebase_source : 3761997a8747b58e3d85bec53097116b9d6e166d --- setuptools/svn_utils.py | 118 ++++++++++++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 50 deletions(-) (limited to 'setuptools/svn_utils.py') diff --git a/setuptools/svn_utils.py b/setuptools/svn_utils.py index dff1c4b0..34adc75e 100644 --- a/setuptools/svn_utils.py +++ b/setuptools/svn_utils.py @@ -1,25 +1,37 @@ import os import re +import sys +from distutils import log +from xml.sax.saxutils import unescape #requires python >= 2.4 from subprocess import Popen as _Popen, PIPE as _PIPE def get_entries_files(base, recurse=True): - for base,dirs,files in os.walk(os.curdir): + for base, dirs, _ in os.walk(os.curdir): if '.svn' not in dirs: dirs[:] = [] continue # no sense walking uncontrolled subdirs dirs.remove('.svn') - f = open(os.path.join(base,'.svn','entries')) + f = open(os.path.join(base, '.svn', 'entries')) yield f.read() f.close() -#It would seem that svn info --xml and svn list --xml were fully supported by 1.3.x -#the special casing of the entry files seem to start at 1.4.x, so if we check -#for xml in entries and then fall back to the command line, this should catch everything. +#It would seem that svn info --xml and svn list --xml were fully +#supported by 1.3.x the special casing of the entry files seem to start at +#1.4.x, so if we check for xml in entries and then fall back to the command +#line, this should catch everything. -#TODO add the text entry back, and make its use dependent on the non existence of svn? +#subprocess is called several times with shell=(sys.platform=='win32') +#see the follow for more information: +# http://bugs.python.org/issue8557 +# http://stackoverflow.com/questions/5658622/ +# python-subprocess-popen-environment-path + + +#TODO add the text entry back, and make its use dependent on the +# non existence of svn? class SVNEntries(object): svn_tool_version = '' @@ -30,12 +42,12 @@ class SVNEntries(object): if not self.svn_tool_version: self.svn_tool_version = self.get_svn_tool_version() - @staticmethod + @staticmethod def get_svn_tool_version(): - proc = _Popen(['svn', 'propget', self.path], + proc = _Popen(['svn', '--version', '--quiet'], stdout=_PIPE, shell=(sys.platform=='win32')) data = unicode(proc.communicate()[0], encoding='utf-8') - if data is not not: + if data: return data.strip() else: return '' @@ -55,13 +67,13 @@ class SVNEntries(object): if data.startswith(']+deleted="true")', re.I) + entries_pattern = re.compile(r'name="([^"]+)"(?![^>]+deleted="true")', + re.I) results = [ unescape(match.group(1)) for match in entries_pattern.finditer(self.data) - if m.group(1) + if match.group(1) ] return results @@ -190,9 +210,9 @@ class SVNEntriesXML(SVNEntries): class SVNEntriesCMD(SVNEntries): entrypathre = re.compile(r']*path="(\.+)">', re.I) entryre = re.compile(r'', re.M or re.I) - urlre = re.compile('(.*?)', re.I) - revre = re.compile(']*revision="(\d+)"', re.I) - namere = re.compile('(.*?)', re.I) + urlre = re.compile(r'(.*?)', re.I) + revre = re.compile(r']*revision="(\d+)"', re.I) + namere = re.compile(r'(.*?)', re.I) def __get_cached_dir_data(self): return self.dir_data @@ -204,9 +224,8 @@ class SVNEntriesCMD(SVNEntries): return bool(self.get_dir_data()) def get_dir_data(self): - #regard the shell argument, see: http://bugs.python.org/issue8557 - # and http://stackoverflow.com/questions/5658622/python-subprocess-popen-environment-path - proc = _Popen(['svn', 'info', '--xml', self.path], + #regarding the shell argument, see: http://bugs.python.org/issue8557 + proc = _Popen(['svn', 'info', '--xml', self.path], stdout=_PIPE, shell=(sys.platform=='win32')) data = unicode(proc.communicate()[0], encoding='utf-8') self.dir_data = self.entryre.findall(data) @@ -214,39 +233,39 @@ class SVNEntriesCMD(SVNEntries): return self.dir_data def get_entries(self): - #regard the shell argument, see: http://bugs.python.org/issue8557 - # and http://stackoverflow.com/questions/5658622/python-subprocess-popen-environment-path - proc = _Popen(['svn', 'list', '--xml', self.path], + #regarding the shell argument, see: http://bugs.python.org/issue8557 + proc = _Popen(['svn', 'list', '--xml', self.path], stdout=_PIPE, shell=(sys.platform=='win32')) data = unicode(proc.communicate()[0], encoding='utf-8') - self.dir_data = self.entryre.findall(data) + self.entries = self.entryre.findall(data) self.get_dir_data = self.__get_cached_dir_data - return self.dir_data + return self.entries def get_url(self): "Get repository URL" - return self.urlre.search(self.get_sections()[0]).group(1) + return self.urlre.search(self.get_entries()[0]).group(1) def parse_revision_numbers(self): - #NOTE: if one has recently committed, the new revision doesn't get updated until SVN update + #NOTE: if one has recently committed, + # the new revision doesn't get updated until SVN update if not self.is_valid(): return list() else: return [ - int(m.group(1)) - for entry in self.get_enteries() + int(m.group(1)) + for entry in self.get_enries() for m in self.revre.finditer(entry) if m.group(1) ] - + def get_undeleted_records(self): #NOTE: Need to parse entities? if not self.is_valid(): return list() else: return [ - m.group(1)) - for entry in self.get_enteries() + m.group(1) + for entry in self.get_entries() for m in self.namere.finditer(entry) if m.group(1) ] @@ -258,8 +277,7 @@ class SVNEntriesCMD(SVNEntries): return '' #regard the shell argument, see: http://bugs.python.org/issue8557 - # and http://stackoverflow.com/questions/5658622/python-subprocess-popen-environment-path - proc = _Popen(['svn', 'propget', self.path], + proc = _Popen(['svn', 'propget', self.path], stdout=_PIPE, shell=(sys.platform=='win32')) try: return unicode(proc.communicate()[0], encoding='utf-8').splitlines() -- cgit v1.2.1