本文整理汇总了Python中osclib.stagingapi.StagingAPI.get_prj_pseudometa方法的典型用法代码示例。如果您正苦于以下问题:Python StagingAPI.get_prj_pseudometa方法的具体用法?Python StagingAPI.get_prj_pseudometa怎么用?Python StagingAPI.get_prj_pseudometa使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osclib.stagingapi.StagingAPI
的用法示例。
在下文中一共展示了StagingAPI.get_prj_pseudometa方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CheckRepo
# 需要导入模块: from osclib.stagingapi import StagingAPI [as 别名]
# 或者: from osclib.stagingapi.StagingAPI import get_prj_pseudometa [as 别名]
class CheckRepo(object):
def __init__(self, apiurl, project, readonly=False, force_clean=False, debug=False):
"""CheckRepo constructor."""
self.apiurl = apiurl
self.project = project
self.staging = StagingAPI(apiurl, self.project)
self.pkgcache = PkgCache(BINCACHE, force_clean=force_clean)
# grouped = { id: staging, }
self.grouped = {}
# groups = { staging: [ids,], }
self.groups = {}
self._staging()
self.readonly = readonly
self.debug_enable = debug
def debug(self, *args):
if not self.debug_enable:
return
print ' '.join([i if isinstance(i, basestring) else pformat(i) for i in args])
def _staging(self):
"""Preload the groups of related request associated by the same
staging project.
"""
for project in self.staging.get_staging_projects():
# Get all the requests identifier for the project
requests = self.staging.get_prj_pseudometa(project)['requests']
requests = [req['id'] for req in requests]
# Note: Originally we recover also the request returned by
# list_requests_in_prj(). I guest that if the staging
# project is working properly, this method do not add any
# new request to the list.
if requests:
self.groups[project] = requests
self.grouped.update({req: project for req in requests})
def get_request_state(self, request_id):
"""Return the current state of the request."""
state = None
url = makeurl(self.apiurl, ('request', str(request_id)))
try:
root = ET.parse(http_GET(url)).getroot()
state = root.find('state').get('name')
except urllib2.HTTPError, e:
print('ERROR in URL %s [%s]' % (url, e))
return state
示例2: TestApiCalls
# 需要导入模块: from osclib.stagingapi import StagingAPI [as 别名]
# 或者: from osclib.stagingapi.StagingAPI import get_prj_pseudometa [as 别名]
class TestApiCalls(unittest.TestCase):
"""
Tests for various api calls to ensure we return expected content
"""
def setUp(self):
"""
Initialize the configuration
"""
self.obs = OBS()
Config('openSUSE:Factory')
self.api = StagingAPI(APIURL, 'openSUSE:Factory')
def tearDown(self):
"""Clean internal cache"""
if hasattr(self.api, '_invalidate_all'):
self.api._invalidate_all()
def test_ring_packages(self):
"""
Validate the creation of the rings.
"""
# our content in the XML files
# test content for listonly ie. list command
ring_packages = {
'elem-ring-0': 'openSUSE:Factory:Rings:0-Bootstrap',
'elem-ring-1': 'openSUSE:Factory:Rings:0-Bootstrap',
'elem-ring-mini': 'openSUSE:Factory:Rings:0-Bootstrap',
'elem-ring-2': 'openSUSE:Factory:Rings:2-TestDVD',
'git': 'openSUSE:Factory:Rings:2-TestDVD',
'wine': 'openSUSE:Factory:Rings:1-MinimalX',
}
self.assertEqual(ring_packages, self.api.ring_packages_for_links)
# test content for real usage
ring_packages = {
'elem-ring-0': 'openSUSE:Factory:Rings:0-Bootstrap',
'elem-ring-1': 'openSUSE:Factory:Rings:1-MinimalX',
'elem-ring-mini': 'openSUSE:Factory:Rings:0-Bootstrap',
'elem-ring-2': 'openSUSE:Factory:Rings:2-TestDVD',
'git': 'openSUSE:Factory:Rings:2-TestDVD',
'wine': 'openSUSE:Factory:Rings:1-MinimalX',
}
self.assertEqual(ring_packages, self.api.ring_packages)
@unittest.skip("no longer approving non-ring packages")
def test_dispatch_open_requests(self):
"""
Test dispatching and closure of non-ring packages
"""
# Get rid of open requests
self.api.dispatch_open_requests()
# Check that we tried to close it
self.assertEqual(httpretty.last_request().method, 'POST')
self.assertEqual(httpretty.last_request().querystring[u'cmd'], [u'changereviewstate'])
# Try it again
self.api.dispatch_open_requests()
# This time there should be nothing to close
self.assertEqual(httpretty.last_request().method, 'GET')
def test_pseudometa_get_prj(self):
"""
Test getting project metadata from YAML in project description
"""
# Try to get data from project that has no metadata
data = self.api.get_prj_pseudometa('openSUSE:Factory:Staging:A')
# Should be empty, but contain structure to work with
self.assertEqual(data, {'requests': []})
# Add some sample data
rq = {'id': '123', 'package': 'test-package'}
data['requests'].append(rq)
# Save them and read them back
self.api.set_prj_pseudometa('openSUSE:Factory:Staging:A', data)
test_data = self.api.get_prj_pseudometa('openSUSE:Factory:Staging:A')
# Verify that we got back the same data
self.assertEqual(data, test_data)
def test_list_projects(self):
"""
List projects and their content
"""
# Prepare expected results
data = []
for prj in self.obs.staging_project:
data.append('openSUSE:Factory:Staging:' + prj)
# Compare the results
self.assertEqual(data, self.api.get_staging_projects())
def test_open_requests(self):
"""
Test searching for open requests
"""
requests = []
#.........这里部分代码省略.........
示例3: TestApiCalls
# 需要导入模块: from osclib.stagingapi import StagingAPI [as 别名]
# 或者: from osclib.stagingapi.StagingAPI import get_prj_pseudometa [as 别名]
class TestApiCalls(unittest.TestCase):
"""
Tests for various api calls to ensure we return expected content
"""
def setUp(self):
"""
Initialize the configuration
"""
self.obs = OBS()
Config("openSUSE:Factory")
self.api = StagingAPI(APIURL, "openSUSE:Factory")
def tearDown(self):
"""Clean internal cache"""
self.api._invalidate_all()
def test_ring_packages(self):
"""
Validate the creation of the rings.
"""
# our content in the XML files
ring_packages = {
"elem-ring-0": "openSUSE:Factory:Rings:0-Bootstrap",
"elem-ring-1": "openSUSE:Factory:Rings:1-MinimalX",
"elem-ring-2": "openSUSE:Factory:Rings:2-TestDVD",
"git": "openSUSE:Factory:Rings:2-TestDVD",
"wine": "openSUSE:Factory:Rings:1-MinimalX",
}
self.assertEqual(ring_packages, self.api.ring_packages)
@unittest.skip("no longer approving non-ring packages")
def test_dispatch_open_requests(self):
"""
Test dispatching and closure of non-ring packages
"""
# Get rid of open requests
self.api.dispatch_open_requests()
# Check that we tried to close it
self.assertEqual(httpretty.last_request().method, "POST")
self.assertEqual(httpretty.last_request().querystring[u"cmd"], [u"changereviewstate"])
# Try it again
self.api.dispatch_open_requests()
# This time there should be nothing to close
self.assertEqual(httpretty.last_request().method, "GET")
def test_pseudometa_get_prj(self):
"""
Test getting project metadata from YAML in project description
"""
# Try to get data from project that has no metadata
data = self.api.get_prj_pseudometa("openSUSE:Factory:Staging:A")
# Should be empty, but contain structure to work with
self.assertEqual(data, {"requests": []})
# Add some sample data
rq = {"id": "123", "package": "test-package"}
data["requests"].append(rq)
# Save them and read them back
self.api.set_prj_pseudometa("openSUSE:Factory:Staging:A", data)
test_data = self.api.get_prj_pseudometa("openSUSE:Factory:Staging:A")
# Verify that we got back the same data
self.assertEqual(data, test_data)
def test_list_projects(self):
"""
List projects and their content
"""
# Prepare expected results
data = []
for prj in self.obs.staging_project:
data.append("openSUSE:Factory:Staging:" + prj)
# Compare the results
self.assertEqual(data, self.api.get_staging_projects())
def test_open_requests(self):
"""
Test searching for open requests
"""
requests = []
# get the open requests
requests = self.api.get_open_requests()
# Compare the results, we only care now that we got 1 of them not the content
self.assertEqual(1, len(requests))
def test_get_package_information(self):
"""
Test if we get proper project, name and revision from the staging informations
"""
package_info = {
"dir_srcmd5": "751efeae52d6c99de48164088a33d855",
"project": "home:Admin",
#.........这里部分代码省略.........
示例4: StagingHelper
# 需要导入模块: from osclib.stagingapi import StagingAPI [as 别名]
# 或者: from osclib.stagingapi.StagingAPI import get_prj_pseudometa [as 别名]
class StagingHelper(object):
def __init__(self, project):
self.project = project
self.apiurl = osc.conf.config['apiurl']
Config(self.apiurl, self.project)
self.api = StagingAPI(self.apiurl, self.project)
def get_support_package_list(self, project, repository):
f = osc.core.get_buildconfig(self.apiurl, project, repository).splitlines()
pkg_list = []
for line in f:
if re.match('Preinstall', line) or re.match('VM[Ii]nstall', line) or re.match('Support', line):
content = line.split(':')
variables = [x.strip() for x in content[1].split(' ')]
for var in variables:
if var != '' and var not in pkg_list:
if var.startswith('!') and var[1:] in pkg_list:
pkg_list.remove(var[1:])
else:
pkg_list.append(var)
return pkg_list
def get_project_binarylist(self, project, repository, arch):
query = {'view': 'binaryversions'}
root = ET.parse(http_GET(makeurl(self.apiurl, ['build', project, repository, arch],
query=query))).getroot()
return root
def process_project_binarylist(self, project, repository, arch):
prj_binarylist = self.get_project_binarylist(project, repository, arch)
files = {}
for package in prj_binarylist.findall('./binaryversionlist'):
for binary in package.findall('binary'):
result = re.match(r'(.*)-([^-]*)-([^-]*)\.([^-\.]+)\.rpm', binary.attrib['name'])
if not result:
continue
bname = result.group(1)
if bname.endswith('-debuginfo') or bname.endswith('-debuginfo-32bit'):
continue
if bname.endswith('-debugsource'):
continue
if bname.startswith('::import::'):
continue
if result.group(4) == 'src':
continue
files[bname] = package.attrib['package'].split(':', 1)[0]
return files
def check_multiple_specs(self, project, packages):
expanded_packages = []
for pkg in packages:
query = {'expand': 1}
url = makeurl(self.apiurl, ['source', project, pkg], query=query)
try:
root = ET.parse(http_GET(url)).getroot()
except HTTPError as e:
if e.code == 404:
continue
raise
for en in root.findall('entry'):
if en.attrib['name'].endswith('.spec'):
expanded_packages.append(en.attrib['name'][:-5])
return expanded_packages
def crawl(self):
"""Main method"""
rebuild_data = self.api.pseudometa_file_load('support_pkg_rebuild')
if rebuild_data is None:
print("There is no support_pkg_rebuild file!")
return
logging.info('Gathering support package list from %s' % self.project)
support_pkgs = self.get_support_package_list(self.project, 'standard')
files = self.process_project_binarylist(self.project, 'standard', 'x86_64')
staging_projects = ["%s:%s"%(self.api.cstaging, p) for p in self.api.get_staging_projects_short()]
cand_sources = defaultdict(list)
for stg in staging_projects:
prj_meta = self.api.get_prj_pseudometa(stg)
prj_staged_packages = [req['package'] for req in prj_meta['requests']]
prj_expanded_packages = self.check_multiple_specs(self.project, prj_staged_packages)
for pkg in support_pkgs:
if files.get(pkg) and files.get(pkg) in prj_expanded_packages:
if files.get(pkg) not in cand_sources[stg]:
cand_sources[stg].append(files.get(pkg))
root = ET.fromstring(rebuild_data)
logging.info('Checking rebuild data...')
for stg in root.findall('staging'):
rebuild = stg.find('rebuild').text
suppkg_list = stg.find('supportpkg').text
need_rebuild = False
suppkgs = []
if suppkg_list:
suppkgs = suppkg_list.split(',')
#.........这里部分代码省略.........