Move out memoized functions.
This commit is contained in:
parent
17a7140ab0
commit
a5c4d1d4b6
@ -21,7 +21,6 @@ from osc import cmdln
|
|||||||
from osc.core import get_binary_file
|
from osc.core import get_binary_file
|
||||||
from osc.core import get_buildinfo
|
from osc.core import get_buildinfo
|
||||||
from osc.core import http_GET
|
from osc.core import http_GET
|
||||||
from osc.core import http_POST
|
|
||||||
from osc.core import makeurl
|
from osc.core import makeurl
|
||||||
from osc.core import Request
|
from osc.core import Request
|
||||||
|
|
||||||
@ -30,50 +29,12 @@ _plugin_dir = os.path.expanduser('~/.osc-plugins')
|
|||||||
sys.path.append(_plugin_dir)
|
sys.path.append(_plugin_dir)
|
||||||
from osclib.checkrepo import CheckRepo
|
from osclib.checkrepo import CheckRepo
|
||||||
from osclib.cycle import CycleDetector
|
from osclib.cycle import CycleDetector
|
||||||
from osclib.memoize import memoize, CACHEDIR
|
from osclib.memoize import CACHEDIR
|
||||||
|
|
||||||
|
|
||||||
# Directory where download binary packages.
|
# Directory where download binary packages.
|
||||||
DOWNLOADS = os.path.expanduser('~/co/downloads')
|
DOWNLOADS = os.path.expanduser('~/co/downloads')
|
||||||
|
|
||||||
#
|
|
||||||
# XXX - Ugly Hack. Because the way that osc import plugings we need to
|
|
||||||
# declare some functions and objects used in the decorator as global
|
|
||||||
#
|
|
||||||
global tempfile
|
|
||||||
global wraps
|
|
||||||
|
|
||||||
global build
|
|
||||||
global last_build_success
|
|
||||||
global jobhistory
|
|
||||||
|
|
||||||
|
|
||||||
@memoize()
|
|
||||||
def build(apiurl, project, repo, arch, package):
|
|
||||||
root = None
|
|
||||||
try:
|
|
||||||
url = makeurl(apiurl, ['build', project, repo, arch, package])
|
|
||||||
root = http_GET(url).read()
|
|
||||||
except urllib2.HTTPError, e:
|
|
||||||
print('ERROR in URL %s [%s]' % (url, e))
|
|
||||||
return root
|
|
||||||
|
|
||||||
|
|
||||||
@memoize()
|
|
||||||
def last_build_success(apiurl, src_project, tgt_project, src_package, rev):
|
|
||||||
root = None
|
|
||||||
try:
|
|
||||||
url = makeurl(apiurl,
|
|
||||||
['build', src_project,
|
|
||||||
'_result?lastsuccess&package=%s&pathproject=%s&srcmd5=%s' % (
|
|
||||||
quote_plus(src_package),
|
|
||||||
quote_plus(tgt_project),
|
|
||||||
rev)])
|
|
||||||
root = http_GET(url).read()
|
|
||||||
except urllib2.HTTPError, e:
|
|
||||||
print('ERROR in URL %s [%s]' % (url, e))
|
|
||||||
return root
|
|
||||||
|
|
||||||
|
|
||||||
def get_project_repos(apiurl, src_project, tgt_project, src_package, rev):
|
def get_project_repos(apiurl, src_project, tgt_project, src_package, rev):
|
||||||
"""Read the repositories of the project from _meta."""
|
"""Read the repositories of the project from _meta."""
|
||||||
@ -160,7 +121,7 @@ def _check_repo_find_submit_request(self, opts, project, package):
|
|||||||
|
|
||||||
|
|
||||||
def _check_repo_avoid_wrong_friends(self, prj, repo, arch, pkg, opts):
|
def _check_repo_avoid_wrong_friends(self, prj, repo, arch, pkg, opts):
|
||||||
xml = build(opts.apiurl, prj, repo, arch, pkg)
|
xml = self.checkrepo.build(prj, repo, arch, pkg)
|
||||||
if xml:
|
if xml:
|
||||||
root = ET.fromstring(xml)
|
root = ET.fromstring(xml)
|
||||||
for binary in root.findall('binary'):
|
for binary in root.findall('binary'):
|
||||||
@ -275,7 +236,7 @@ def _check_repo_one_request(self, rq, opts):
|
|||||||
|
|
||||||
|
|
||||||
def _check_repo_buildsuccess(self, p, opts):
|
def _check_repo_buildsuccess(self, p, opts):
|
||||||
root_xml = last_build_success(opts.apiurl, p.sproject, p.tproject, p.spackage, p.rev)
|
root_xml = self.checkrepo.last_build_success(p.sproject, p.tproject, p.spackage, p.rev)
|
||||||
root = ET.fromstring(root_xml)
|
root = ET.fromstring(root_xml)
|
||||||
if not root:
|
if not root:
|
||||||
return False
|
return False
|
||||||
@ -695,7 +656,7 @@ def do_check_repo(self, subcmd, opts, *args):
|
|||||||
for request in self.checkrepo.pending_requests():
|
for request in self.checkrepo.pending_requests():
|
||||||
packs.extend(self._check_repo_one_request(request, opts))
|
packs.extend(self._check_repo_one_request(request, opts))
|
||||||
else:
|
else:
|
||||||
# we have a list, use them.
|
# We have a list, use them.
|
||||||
for request_id in ids:
|
for request_id in ids:
|
||||||
request = self.checkrepo.get_request(request_id)
|
request = self.checkrepo.get_request(request_id)
|
||||||
packs.extend(self._check_repo_one_request(request, opts))
|
packs.extend(self._check_repo_one_request(request, opts))
|
||||||
|
@ -14,14 +14,15 @@
|
|||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
from urllib import quote_plus
|
||||||
import urllib2
|
import urllib2
|
||||||
from xml.etree import cElementTree as ET
|
from xml.etree import cElementTree as ET
|
||||||
|
|
||||||
from osc.core import http_GET
|
from osc.core import http_GET
|
||||||
from osc.core import http_POST
|
from osc.core import http_POST
|
||||||
from osc.core import makeurl
|
from osc.core import makeurl
|
||||||
|
|
||||||
from osclib.stagingapi import StagingAPI
|
from osclib.stagingapi import StagingAPI
|
||||||
|
from osclib.memoize import memoize
|
||||||
|
|
||||||
|
|
||||||
class CheckRepo(object):
|
class CheckRepo(object):
|
||||||
@ -97,3 +98,30 @@ class CheckRepo(object):
|
|||||||
except urllib2.HTTPError, e:
|
except urllib2.HTTPError, e:
|
||||||
print('ERROR in URL %s [%s]' % (url, e))
|
print('ERROR in URL %s [%s]' % (url, e))
|
||||||
return requests
|
return requests
|
||||||
|
|
||||||
|
@memoize()
|
||||||
|
def build(self, project, repo, arch, package):
|
||||||
|
"""Return the build XML document from OBS."""
|
||||||
|
xml = None
|
||||||
|
try:
|
||||||
|
url = makeurl(self.apiurl, ('build', project, repo, arch, package))
|
||||||
|
xml = http_GET(url).read()
|
||||||
|
except urllib2.HTTPError, e:
|
||||||
|
print('ERROR in URL %s [%s]' % (url, e))
|
||||||
|
return xml
|
||||||
|
|
||||||
|
@memoize()
|
||||||
|
def last_build_success(self, src_project, tgt_project, src_package, rev):
|
||||||
|
"""Return the last build success XML document from OBS."""
|
||||||
|
xml = None
|
||||||
|
try:
|
||||||
|
url = makeurl(self.apiurl,
|
||||||
|
('build', src_project,
|
||||||
|
'_result?lastsuccess&package=%s&pathproject=%s&srcmd5=%s' % (
|
||||||
|
quote_plus(src_package),
|
||||||
|
quote_plus(tgt_project),
|
||||||
|
rev)))
|
||||||
|
xml = http_GET(url).read()
|
||||||
|
except urllib2.HTTPError, e:
|
||||||
|
print('ERROR in URL %s [%s]' % (url, e))
|
||||||
|
return xml
|
||||||
|
Loading…
x
Reference in New Issue
Block a user