Declare global some references

This commit is contained in:
Alberto Planas 2013-07-24 16:54:55 +02:00
parent b267fb3abf
commit 7a0fe68e39

View File

@ -9,22 +9,33 @@ import cPickle
from datetime import datetime from datetime import datetime
from functools import wraps from functools import wraps
import os import os
import shelve
import re import re
import subprocess import subprocess
import shelve
import shutil import shutil
from urllib import quote_plus 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 import oscerr, cmdln from osc import oscerr
from osc.core import (get_binary_file, from osc import cmdln
get_buildinfo,
http_GET, from osc.core import get_binary_file
http_POST, from osc.core import get_buildinfo
makeurl, from osc.core import http_GET
Request) from osc.core import http_POST
from osc.core import makeurl
from osc.core import Request
#
# Ugly hack -- because the way that osc import plugings we need to
# declase some functions and objects used in the decorator as global
#
global cPickle
global datetime
global shelve
global wraps
def memoize(f): def memoize(f):
@ -114,6 +125,8 @@ def memoize(f):
cache = shelve.open(cache_name, protocol=-1) cache = shelve.open(cache_name, protocol=-1)
return _f return _f
global memoize
def _check_repo_change_review_state(self, opts, id_, newstate, message='', supersed=None): def _check_repo_change_review_state(self, opts, id_, newstate, message='', supersed=None):
"""Taken from osc/osc/core.py, improved: """Taken from osc/osc/core.py, improved:
@ -176,7 +189,7 @@ def _check_repo_avoid_wrong_friends(self, prj, repo, arch, pkg, opts):
try: try:
url = makeurl(opts.apiurl, ["build", prj, repo, arch, pkg]) url = makeurl(opts.apiurl, ["build", prj, repo, arch, pkg])
root = ET.parse(http_GET(url)).getroot() root = ET.parse(http_GET(url)).getroot()
except urllib2.HTTPError: except urllib2.HTTPError, e:
print 'ERROR in URL %s [%s]'%(url, e) print 'ERROR in URL %s [%s]'%(url, e)
return False return False
for binary in root.findall('binary'): for binary in root.findall('binary'):
@ -311,19 +324,19 @@ def last_build_success(apiurl, src_project, tgt_project, src_package, rev):
'_result?lastsuccess&package=%s&pathproject=%s&srcmd5=%s'%(quote_plus(src_package), '_result?lastsuccess&package=%s&pathproject=%s&srcmd5=%s'%(quote_plus(src_package),
quote_plus(tgt_project), quote_plus(tgt_project),
rev)]) rev)])
root = ET.parse(http_GET(url)).getroot() root = http_GET(url).read()
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 root return root
global last_build_success
def _check_repo_buildsuccess(self, p, opts): def _check_repo_buildsuccess(self, p, opts):
root = last_build_success(opts.apiurl, p.sproject, p.tproject, p.spackage, p.rev) root_xml = last_build_success(opts.apiurl, p.sproject, p.tproject, p.spackage, p.rev)
root = ET.fromstring(root_xml)
if not root: if not root:
return False return False
if 'code' in root.attrib: if 'code' in root.attrib:
print ET.tostring(root) print ET.tostring(root)
return False return False