home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import os
- import re
- import subprocess
- import apt_pkg
- import libxml2
- import urlparse
- from exceptions import LaunchpadURLError, PythonLaunchpadBugsValueError
- from lpconstants import BASEURL
-
- try:
- from bzrlib.branch import Branch
- from bzrlib import trace
- HAVE_BZR = True
- except:
- HAVE_BZR = False
-
-
- def get_version_from_changelog(path):
- changelog = os.path.join(path, 'debian/changelog')
- if os.path.exists(changelog):
- head = open(changelog).readline()
- match = re.compile('.*\\((.*)\\).*').match(head)
- if match:
- return match.group(1)
-
- return 'unknown'
-
-
- def noerr(ctx, str):
- pass
-
- libxml2.registerErrorHandler(noerr, None)
-
- def find_version_number(show_nick = False):
- path = os.path.join(os.path.dirname(__file__), '..')
- if path.startswith('/usr'):
- output = subprocess.Popen([
- 'dpkg-query',
- '-W',
- 'python-launchpad-bugs'], stdout = subprocess.PIPE).communicate()[0]
-
- try:
- return output.split()[1]
- return 'unknown'
-
-
- if HAVE_BZR:
-
- try:
- trace.be_quiet()
- trace.enable_default_logging()
- version = get_version_from_changelog(path)
- if os.path.islink(os.path.dirname(__file__)):
- path = os.path.realpath(os.path.dirname(__file__))
-
- branch = Branch.open_containing(path)[0]
- bzr_revno = branch.revno()
- if show_nick:
- nick = branch.nick
- return '%sr%s, branch nick: %s' % (version, bzr_revno, nick)
- return '%sr%s' % (version, bzr_revno)
-
-
- return 'unknown'
-
-
- def package_exists(package_name):
-
- try:
- apt_pkg.init()
- sources = apt_pkg.GetPkgSrcRecords()
- sources.Restart()
- if not sources.Lookup(str(package_name)):
- return False
- return True
- except:
- print "You must put some 'source' URIs in your sources.list"
- return False
-
-
-
- def lazy_makedir(directory):
-
- try:
- os.makedirs(directory)
- except:
- pass
-
-
-
- def remove_obsolete_attachments(path, open_bugs):
- open_bug_nrs = set(map((lambda a: str(a.nr)), open_bugs))
- if os.path.exists(path):
- bugs = set((filter,)((lambda a: os.path.isdir(os.path.join(path, a))), os.listdir(path)))
- for bug in bugs.difference(bugs.intersection(open_bug_nrs)):
- bug_path = os.path.join(path, bug)
- if os.path.isdir(bug_path):
- os.system('rm -r %s' % bug_path)
- continue
-
-
-
-
- def bugnumber_to_url(nr):
- return '%s/bugs/%s' % (BASEURL.BUG, nr)
-
-
- def valid_lp_url(url, type):
- """ validates given 'url' against 'type'
- raises PythonLaunchpadBugsValueError for invalid url and modifies
- if necessary. Currently only validation for 'scheme' and 'netloc'
- part of the url is implemented, path needs to be done but is more
- complicated.
- """
- if not url:
- raise PythonLaunchpadBugsValueError(msg = 'url is empty')
- url
- (scheme, netloc, path, query, fragment) = urlparse.urlsplit(url)
- (_, type, x, _, _) = urlparse.urlsplit(type)
- if not type:
- type = x
-
- if not type:
- raise AssertionError, 'unable to validate against given type'
- if not scheme and not netloc:
- if not path.startswith('/'):
- scheme = 'http'
- x = path.split('/', 1)
- if len(x) == 1:
- netloc = x[0]
- path = ''
- else:
- netloc = x[0]
- path = x[1]
-
-
- if not scheme or scheme == 'http':
- scheme = 'https'
-
- if scheme not in ('http', 'https'):
- raise PythonLaunchpadBugsValueError(values = {
- 'url': url,
- 'type': type }, msg = 'Wrong schema')
- scheme not in ('http', 'https')
- if not netloc:
- netloc = type
- else:
- n = netloc
- prefix = None
- if 'edge.' in netloc:
- n = netloc.replace('edge.', '')
- prefix = 'edge'
- elif 'staging.' in netloc:
- n = netloc.replace('staging.', '')
- prefix = 'staging'
-
- if n != type:
- if n == 'launchpad.net':
- netloc = type
- if prefix:
- netloc = netloc.replace('.launchpad', '.%s.launchpad' % prefix)
-
- else:
- raise PythonLaunchpadBugsValueError(values = {
- 'url': url,
- 'type': type }, msg = 'Wrong type')
- n == 'launchpad.net'
- return urlparse.urlunsplit((scheme, netloc, path, query, fragment))
-
-
- def debug(*arg, **args):
- for i in arg:
- if type(i) == type(dict()):
- for k in i:
- print '%s : %s' % (k, i[k])
-
- print i
-
- for k in args:
- print k, args[k]
-
-
-
- def get_open_milestones(dist = None, package = None, project = None):
- url = BASEURL.BUG
- if dist:
- url += '/%s' % dist
- if package:
- url += '/+source/%s' % package
-
- elif project:
- url += '/%s' % project
- else:
- raise TypeError, 'Wrong number of arguments'
- dist += '/+bugs?advanced=1'
-
- try:
- HTTPConnection = HTTPConnection
- import http_connection
- text = HTTPConnection().get(url).text
- except LaunchpadURLError:
- raise PythonLaunchpadBugsValueError({
- 'get_open_milestones': "Can't find milestones for (dist=%s, package=%s, project=%s)" % (dist, package, project) }, url)
-
- ctx = libxml2.htmlParseDoc(text, 'UTF-8')
- milestones = ctx.xpathEval('//input[@name="field.milestone:list"]')
- for m in milestones:
- identifier = m.prop('id').split('.', 1).pop()
- yield (identifier, int(m.prop('value')))
- x = identifier.split(' ')[1:]
- if x:
- yield (' '.join(x), int(m.prop('value')))
- continue
-
-
-