Author: bugman Date: Fri May 23 12:11:36 2014 New Revision: 23374 URL: http://svn.gna.org/viewcvs/relax?rev=23374&view=rev Log: Large speed up for the relax start up times for svn and git-svn copies of the relax repository. The 'svn info' and 'git svn info' commands are now only executed once when the version module is first imported. The revision() and url() functions have been merged into the repo_info() function and this is called when the module is imported. This repo_info() function stores the repository revision and URL as the version.repo_revision and version.repo_url module variables. It also catches if these variables are already set, so that multiple imports of the module do not cause the repository information to be looked up each time. Previously the revision() and url() functions where called every time a relax state or result file was created, hence for repository copies the 'svn info' or 'git svn info' commands were being called each time. The functions were also called for each interpreter object instantiated, and for each import of the version module. Modified: trunk/data_store/__init__.py trunk/info.py trunk/version.py Modified: trunk/data_store/__init__.py URL: http://svn.gna.org/viewcvs/relax/trunk/data_store/__init__.py?rev=23374&r1=23373&r2=23374&view=diff ============================================================================== --- trunk/data_store/__init__.py (original) +++ trunk/data_store/__init__.py Fri May 23 12:11:36 2014 @@ -597,12 +597,10 @@ top_element.setAttribute('version', version.version) top_element.setAttribute('time', asctime()) top_element.setAttribute('file_version', "2") - rev = version.revision() - if rev: - top_element.setAttribute('revision', rev) - url = version.url() - if url: - top_element.setAttribute('url', url) + if version.repo_revision: + top_element.setAttribute('revision', version.repo_revision) + if version.repo_url: + top_element.setAttribute('url', version.repo_url) # Add all objects in the data store base object to the XML element. if all: Modified: trunk/info.py URL: http://svn.gna.org/viewcvs/relax/trunk/info.py?rev=23374&r1=23373&r2=23374&view=diff ============================================================================== --- trunk/info.py (original) +++ trunk/info.py Fri May 23 12:11:36 2014 @@ -47,7 +47,7 @@ # relax module imports. from status import Status; status = Status() -from version import revision, url, version, version_full +from version import repo_revision, repo_url, version, version_full def print_sys_info(): @@ -283,8 +283,8 @@ # Program name and version - subversion code. if version == 'repository checkout': - text = "%s %s r%s" % (self.title, self.version, revision()) - text2 = "%s" % (url()) + text = "%s %s r%s" % (self.title, self.version, repo_revision) + text2 = "%s" % (repo_url) intro_string = intro_string + self.centre(text, status.text_width) + '\n' + self.centre(text2, status.text_width) + '\n\n' # Program name and version - official releases. Modified: trunk/version.py URL: http://svn.gna.org/viewcvs/relax/trunk/version.py?rev=23374&r1=23373&r2=23374&view=diff ============================================================================== --- trunk/version.py (original) +++ trunk/version.py Fri May 23 12:11:36 2014 @@ -41,114 +41,51 @@ repo_url = None -def revision(): - """Attempt to retrieve the SVN revision number, if this is a checked out copy. +def repo_information(): + """Determine the subversion revision number and URL from svn or git-svn copies of the repository.""" - @return: The SVN revision number, or None if unsuccessful. - @rtype: None or str - """ + # The global variables + global repo_revision + global repo_url - # 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): + # The variables are already set, so do nothing. + if repo_revision != None or repo_url != None: return # Python 2.3 and earlier. if Popen == None: return - # Try to run 'svn info', reading the output if there are no errors. - pipe = Popen('svn info %s' % status.install_path, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False) - if not pipe.stderr.readlines(): - # Loop over the output lines. - for line in pipe.stdout.readlines(): - # Decode Python 3 byte arrays. - if hasattr(line, 'decode'): - line = line.decode() + # The command to use. + cmd = None + if access(status.install_path+sep+'.svn', F_OK): + cmd = 'svn info %s' % status.install_path + elif access(status.install_path+sep+'.git', F_OK): + cmd = 'cd %s; git svn info' % status.install_path - # Split up the line. - row = line.split() - - # Store revision as the global variable and return it. - if len(row) and row[0] == 'Revision:': - 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) - if not pipe.stderr.readlines(): - # Loop over the output lines. - for line in pipe.stdout.readlines(): - # Decode Python 3 byte arrays. - if hasattr(line, 'decode'): - line = line.decode() - - # Split up the line. - row = line.split() - - # Store revision as the global variable and return it. - if len(row) and row[0] == 'Revision:': - repo_revision = str(row[1]) - return repo_revision - - -def url(): - """Attempt to retrieve the SVN URL, if this is a checked out copy. - - @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): + # Not a repository copy, so do nothing. + if not cmd: return - # Python 2.3 and earlier. - if Popen == None: - return + # Open the pipe and run the command. + pipe = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False) - # Try to run 'svn info', reading the output if there are no errors. - pipe = Popen('svn info %s' % status.install_path, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False) - if not pipe.stderr.readlines(): - # Loop over the output lines. - for line in pipe.stdout.readlines(): - # Decode Python 3 byte arrays. - if hasattr(line, 'decode'): - line = line.decode() + # Loop over the output lines. + for line in pipe.stdout.readlines(): + # Decode Python 3 byte arrays. + if hasattr(line, 'decode'): + line = line.decode() - # Split up the line. - row = line.split() + # Split up the line. + row = line.split() - # Store URL as the global variable and return it. - if len(row) and row[0] == 'URL:': - repo_url = str(row[1]) - return repo_url + # Store revision as the global variable. + if len(row) and row[0] == 'Revision:': + repo_revision = str(row[1]) - # 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) - if not pipe.stderr.readlines(): - # Loop over the output lines. - for line in pipe.stdout.readlines(): - # Decode Python 3 byte arrays. - if hasattr(line, 'decode'): - line = line.decode() - - # Split up the line. - row = line.split() - - # Store URL as the global variable and return it. - if len(row) and row[0] == 'URL:': - repo_url = str(row[1]) - return repo_url + # Store URL as the global variable. + if len(row) and row[0] == 'URL:': + repo_url = str(row[1]) def version_full(): @@ -163,15 +100,19 @@ # Repository version. if ver == 'repository checkout': - # Get the SVN revision and URL. - svn_rev = revision() - svn_url = url() + # The global variables + global repo_revision + global repo_url # Change the version string. - if svn_rev: - ver = version + " r" + svn_rev - if svn_url: - ver = ver + " " + svn_url + if repo_revision != None: + ver = version + " r" + repo_revision + if repo_url != None: + ver = ver + " " + repo_url # Return the version. return ver + + +# Fetch the repository information, if present. +repo_information()