Skip to content

Commit

Permalink
- osc.wc.project, osc.wc.util, test.httptest: beautify "global" usage
Browse files Browse the repository at this point in the history
Move "global" statements to the top of a method
  • Loading branch information
marcus-h committed Feb 26, 2014
1 parent 13d0c03 commit de96443
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion osc/wc/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ def _perform_adds(self, ustate, **kwargs):
self.notifier.processed(package, ' ', None)

def _perform_deletes(self, ustate):
uinfo = ustate.info
global _STORE
uinfo = ustate.info
for package in uinfo.deleted:
st = self._status(package)
# a delete is always possible
Expand Down
10 changes: 5 additions & 5 deletions osc/wc/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def lock(self):
has a lock on the working copy.
"""
global _LOCK
if self.has_lock():
# a double lock is no problem at all but if it occurs
# it smells like a programming/logic error (IMHO)
raise RuntimeError('Double lock occured')
global _LOCK
lock = _storefile(self._path, _LOCK)
f = open(lock, 'w')
fcntl.lockf(f, fcntl.LOCK_EX)
Expand All @@ -100,12 +100,12 @@ def unlock(self):
RuntimeError is raised.
"""
global _LOCK
if not self.has_lock():
raise RuntimeError('Attempting to release an unaquired lock.')
fcntl.lockf(self._fobj, fcntl.LOCK_UN)
self._fobj.close()
self._fobj = None
global _LOCK
lock = _storefile(self._path, _LOCK)
os.unlink(lock)

Expand Down Expand Up @@ -348,11 +348,11 @@ def __init__(self, path, name, initial_state, info=None,
states -- maps each wc file to its current state
"""
global _PKG_DATA
if ((info is not None and xml_data)
or (info is None and xml_data is None)):
raise ValueError('either specify info or xml_data')
super(XMLTransactionState, self).__init__(path)
global _PKG_DATA
trans_dir = _storefile(self._path, XMLTransactionState.DIR)
data_dir = os.path.join(trans_dir, _PKG_DATA)
self._location = data_dir
Expand Down Expand Up @@ -521,13 +521,13 @@ def missing_storepaths(path, *paths, **kwargs):
"""
global _PKG_DATA
dirs = kwargs.get('dirs', False)
data = kwargs.get('data', False)
if not _has_storedir(path):
return list(paths)
storedir = _storedir(path)
if data:
global _PKG_DATA
storedir = _storefile(path, _PKG_DATA)
missing = []
for p in paths:
Expand Down Expand Up @@ -756,6 +756,7 @@ def wc_init(path, ext_storedir=None):
ext_storedir.
"""
global _PKG_DATA
if (ext_storedir is not None and
(not os.path.isdir(ext_storedir) or
not os.access(ext_storedir, os.W_OK))):
Expand Down Expand Up @@ -785,7 +786,6 @@ def wc_init(path, ext_storedir=None):
else:
os.mkdir(storedir)
wc_write_version(path)
global _PKG_DATA
data_path = _storefile(path, _PKG_DATA)
os.mkdir(data_path)

Expand Down
2 changes: 1 addition & 1 deletion test/httptest.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def fixture_file(self, *paths):
return os.path.abspath(path)

def setUp(self):
super(MockUrllib2Request, self).setUp()
global EXPECTED_REQUESTS
super(MockUrllib2Request, self).setUp()
EXPECTED_REQUESTS = []
self._orig_build_opener = urllib2.build_opener
def build_opener(*handlers):
Expand Down

0 comments on commit de96443

Please sign in to comment.