""" This software was developed by the University of Tennessee as part of the Distributed Data Analysis of Neutron Scattering Experiments (DANSE) project funded by the US National Science Foundation. See the license text in license.txt copyright 2010, University of Tennessee """ import sys, time import subprocess, os import getopt from threading import Thread ## Maximum number of seconds to wait for an answer from the server MAX_WAIT_TIME = 20 ## Local storage file name VERSION_FILE = '.current_version' class VersionChecker(object): """ Class of objects used to obtain the current version of an application from the deployment server. A sub process is started to read the URL associated with the version number. The version number is written on file locally before the reading process ends, then read when the version number is requested. The reading of the URL is put in a separate process so that it doesn't affect the performance of the application and can be managed and stopped at any time. """ ## Process used to obtain the current application version from the server _process = None ## Start time of the process of obtaining a version number _t_0 = None def __init__(self, version_url): """ Start the sub-process used to read the version URL """ self._process = subprocess.Popen([sys.executable, __file__, '-g', '-u%s' % version_url]) self._t_0 = time.time() def is_complete(self): """ Method used to poll the reading process. The process will be killed if the wait time is longer than a predefined maximum. This method should always be called before get_version() to ensure accuracy of the version number that is returned. """ if(time.time()-self._t_00: write_version(version) return write_version('0.0.0') except: write_version('0.0.0') if __name__ == "__main__": _get_version = False _url = 'http://danse.chem.utk.edu/prview_version.php' opts, args = getopt.getopt(sys.argv[1:], "gu:", ["get", "url="]) for opt, arg in opts: if opt in ("-u", "--url"): _url = arg elif opt in ("-g", "--get"): _get_version = True if _get_version: # Get the version number from the URL. _get_version_from_server(_url) else: # Test execution of the reading process def _process(version, baggage=None): print "Received:", version checker = VersionThread(_url, _process) checker.start()