Author: bugman Date: Fri May 23 11:25:34 2014 New Revision: 23373 URL: http://svn.gna.org/viewcvs/relax?rev=23373&view=rev Log: Speed up for the version module when using a repository copy of the code. The repository revision and URL and now stored as module variables, so that the 'svn info' and 'git svn info' commands are only run twice, once for the revision() function and once for the url() function. Modified: trunk/version.py Modified: trunk/version.py URL: http://svn.gna.org/viewcvs/relax/trunk/version.py?rev=23373&r1=23372&r2=23373&view=diff ============================================================================== --- trunk/version.py (original) +++ trunk/version.py Fri May 23 11:25:34 2014 @@ -37,6 +37,8 @@ version = "repository checkout" +repo_revision = None +repo_url = None def revision(): @@ -45,6 +47,11 @@ @return: The SVN revision number, or None if unsuccessful. @rtype: None or str """ + + # Return the global variable, if set. + global repo_revision + if repo_revision != None: + return repo_revision # Does the base directory exist (i.e. is this a checked out copy). if not access(status.install_path+sep+'.svn', F_OK) and not access(status.install_path+sep+'.git', F_OK): @@ -66,9 +73,10 @@ # Split up the line. row = line.split() - # The revision. + # Store revision as the global variable and return it. if len(row) and row[0] == 'Revision:': - return str(row[1]) + repo_revision = str(row[1]) + return repo_revision # Try git-svn, reading the output if there are no errors. pipe = Popen('cd %s; git svn info' % status.install_path, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False) @@ -82,9 +90,10 @@ # Split up the line. row = line.split() - # The revision. + # Store revision as the global variable and return it. if len(row) and row[0] == 'Revision:': - return str(row[1]) + repo_revision = str(row[1]) + return repo_revision def url(): @@ -93,6 +102,11 @@ @return: The SVN URL, or None if unsuccessful. @rtype: None or str """ + + # Return the global variable, if set. + global repo_url + if repo_url != None: + return repo_url # Does the base directory exist (i.e. is this a checked out copy). if not access(status.install_path+sep+'.svn', F_OK) and not access(status.install_path+sep+'.git', F_OK): @@ -114,9 +128,10 @@ # Split up the line. row = line.split() - # The revision. + # Store URL as the global variable and return it. if len(row) and row[0] == 'URL:': - return str(row[1]) + repo_url = str(row[1]) + return repo_url # Try git-svn, reading the output if there are no errors. pipe = Popen('cd %s; git svn info' % status.install_path, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False) @@ -130,9 +145,10 @@ # Split up the line. row = line.split() - # The revision. + # Store URL as the global variable and return it. if len(row) and row[0] == 'URL:': - return str(row[1]) + repo_url = str(row[1]) + return repo_url def version_full():