From 3ca40914267f96e5edca7c4a1c76155b64a4a571 Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Tue, 3 Aug 2010 20:49:50 +0200 Subject: Remove function call results as default param values The function call is evaluated once when the module code is read. However, the os.getcwd() function might give different results at run time than at module reading time. Replaced those default param values with None, and let the functions call os.getcwd() if the param happens to be None. --- src/pyfedpkg/__init__.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/pyfedpkg/__init__.py b/src/pyfedpkg/__init__.py index ecb111d..fe4f3a0 100644 --- a/src/pyfedpkg/__init__.py +++ b/src/pyfedpkg/__init__.py @@ -183,9 +183,11 @@ def _get_build_arches_from_srpm(srpm, arches): raise FedpkgError('No compatible build arches found in %s' % srpm) return archlist -def _list_branches(path=os.getcwd(), repo=None): +def _list_branches(path=None, repo=None): """Returns a tuple of local and remote branch names""" + if not path: + path = os.getcwd() # Create the repo from path if no repo passed if not repo: repo = git.Repo(path) @@ -278,7 +280,7 @@ def clean(dry=False, useignore=True): log.error(error) return proc.returncode -def clone(module, user, path=os.getcwd(), branch=None, bare_dir=None): +def clone(module, user, path=None, branch=None, bare_dir=None): """Clone a repo, optionally check out a specific branch. module is the name of the module to clone @@ -294,6 +296,8 @@ def clone(module, user, path=os.getcwd(), branch=None, bare_dir=None): """ + if not path: + path = os.getcwd() # construct the git url if user: giturl = GITBASEURL % {'user': user, 'module': module} @@ -324,7 +328,7 @@ def clone(module, user, path=os.getcwd(), branch=None, bare_dir=None): _run_command(cmd) return -def clone_with_dirs(module, user, path=os.getcwd()): +def clone_with_dirs(module, user, path=None): """Clone a repo old style with subdirs for each branch. module is the name of the module to clone @@ -333,6 +337,8 @@ def clone_with_dirs(module, user, path=os.getcwd()): """ + if not path: + path = os.getcwd() # Get the full path of, and git object for, our directory of branches top_path = os.path.join(path, module) top_git = git.Git(top_path) @@ -396,7 +402,7 @@ def get_latest_commit(module): # Return the hash sum return output.split()[0] -def import_srpm(srpm, path=os.getcwd()): +def import_srpm(srpm, path=None): """Import the contents of an srpm into a repo. srpm: File to import contents from @@ -411,6 +417,8 @@ def import_srpm(srpm, path=os.getcwd()): """ + if not path: + path = os.getcwd() # see if the srpm even exists srpm = os.path.abspath(srpm) if not os.path.exists(srpm): @@ -474,9 +482,11 @@ def import_srpm(srpm, path=os.getcwd()): os.chdir(oldpath) return(uploadfiles) -def new(path=os.getcwd()): +def new(path=None): """Return changes in a repo since the last tag""" + if not path: + path = os.getcwd() # setup the repo object based on our path try: repo = git.Repo(path) @@ -545,7 +555,7 @@ def sources(path, outdir=None): raise FedpkgError('%s failed checksum' % file) return -def switch_branch(branch, path=os.getcwd()): +def switch_branch(branch, path=None): """Switch the working branch Will create a local branch if one doesn't already exist, @@ -554,6 +564,9 @@ def switch_branch(branch, path=os.getcwd()): Logs output and returns nothing. """ + if not path: + path = os.getcwd() + # setup the repo object based on our path try: repo = git.Repo(path) @@ -760,9 +773,11 @@ class PackageModule: return subprocess.Popen(['rpm --eval %{_arch}'], shell=True, stdout=subprocess.PIPE).communicate()[0].strip('\n') - def __init__(self, path=os.getcwd()): + def __init__(self, path=None): # Initiate a PackageModule object in a given path # Set some global variables used throughout + if not path: + path = os.getcwd() log.debug('Creating module object from %s' % path) self.path = path self.lookaside = LOOKASIDE -- cgit