2003-07-25 22:15:12 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
2003-09-05 21:53:46 +00:00
|
|
|
"""
|
2005-07-21 08:24:09 +00:00
|
|
|
Scans apps dir for application versions
|
2005-01-27 22:29:06 +00:00
|
|
|
and updates the database as appropriate.
|
2003-07-25 22:15:12 +00:00
|
|
|
|
2003-10-03 06:46:22 +00:00
|
|
|
config.xml must contain an <app_dir> which specifies the directory to search.
|
2003-09-05 21:53:46 +00:00
|
|
|
|
|
|
|
apps/APPLICATION_NAME/ contains application versions for each application.
|
|
|
|
|
2007-07-20 20:19:35 +00:00
|
|
|
See http://boinc.berkeley.edu/trac/wiki/UpdateVersions
|
2003-09-05 21:53:46 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
2004-12-06 22:41:19 +00:00
|
|
|
import database, db_mid, configxml, tools
|
2007-10-09 22:58:49 +00:00
|
|
|
import sys, os, re, time, string
|
2003-09-05 21:53:46 +00:00
|
|
|
|
2003-10-26 06:43:47 +00:00
|
|
|
verbose = 0
|
|
|
|
try:
|
|
|
|
if sys.argv[1] == '-v':
|
|
|
|
verbose = 1
|
2003-10-28 00:54:03 +00:00
|
|
|
print '(verbose mode)'
|
2003-10-26 06:43:47 +00:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2003-09-05 21:53:46 +00:00
|
|
|
config = configxml.default_config().config
|
|
|
|
database.connect()
|
|
|
|
|
|
|
|
create_time = int(time.time())
|
|
|
|
|
2005-01-27 22:29:06 +00:00
|
|
|
assert(config.app_dir and config.download_dir and config.download_url)
|
2003-07-25 22:15:12 +00:00
|
|
|
|
2003-09-05 21:53:46 +00:00
|
|
|
objects_to_commit = []
|
|
|
|
|
2003-10-28 00:54:03 +00:00
|
|
|
def xlistdir(dir):
|
|
|
|
return map(lambda file: os.path.join(dir, file), os.listdir(dir))
|
|
|
|
|
2007-10-09 22:58:49 +00:00
|
|
|
def get_api_version(exec_file):
|
|
|
|
tmpfile = '.uvtemp'
|
|
|
|
cmd = "strings %s | grep API_VERSION > %s"%(exec_file, tmpfile)
|
|
|
|
os.system(cmd)
|
|
|
|
f = open(tmpfile, 'r')
|
|
|
|
if (f):
|
|
|
|
s = string.strip(f.read())
|
|
|
|
f.close()
|
|
|
|
os.unlink(tmpfile)
|
|
|
|
prefix = 'API_VERSION_'
|
|
|
|
n = string.find(s, prefix)
|
|
|
|
if (n == 0):
|
|
|
|
k = len(prefix)
|
|
|
|
return s[k:]
|
|
|
|
return ''
|
|
|
|
|
2005-01-27 22:29:06 +00:00
|
|
|
def add_files(
|
2007-10-09 22:58:49 +00:00
|
|
|
app, # the entry from application DB table
|
2005-01-27 23:09:19 +00:00
|
|
|
match, # the output of re_match_exec_filename(exec_files[0])
|
2007-10-09 22:58:49 +00:00
|
|
|
exec_files, # executable files; entry 0 is the main program
|
2005-01-27 23:09:19 +00:00
|
|
|
non_exec_files=[], # non-executable files
|
|
|
|
signature_files={},
|
2008-03-19 16:54:36 +00:00
|
|
|
file_ref_infos = {},
|
|
|
|
extra_xml = ''
|
2005-01-27 22:29:06 +00:00
|
|
|
):
|
2005-07-21 08:24:09 +00:00
|
|
|
''' add files to app.
|
2003-10-26 07:29:03 +00:00
|
|
|
'''
|
|
|
|
assert(match)
|
2005-01-27 23:09:19 +00:00
|
|
|
assert(exec_files[0])
|
2008-03-13 22:57:24 +00:00
|
|
|
version_major, version_minor, platform_name, plan_class = match.groups()
|
|
|
|
if plan_class:
|
2008-03-27 18:25:29 +00:00
|
|
|
plan_class = plan_class[2:] # drop leading __
|
2003-10-26 07:29:03 +00:00
|
|
|
version_num = int(version_major) * 100 + int(version_minor)
|
|
|
|
|
2005-01-27 23:09:19 +00:00
|
|
|
file_base = os.path.basename(exec_files[0])
|
2003-10-26 07:29:03 +00:00
|
|
|
platforms = database.Platforms.find(name = platform_name)
|
|
|
|
if not platforms:
|
|
|
|
print >>sys.stderr, " Unknown platform '%s' for file %s" %(platform_name, file_base)
|
2003-10-26 07:32:42 +00:00
|
|
|
return
|
2003-10-26 07:29:03 +00:00
|
|
|
platform = platforms[0]
|
2003-09-05 21:53:46 +00:00
|
|
|
|
2007-10-09 22:58:49 +00:00
|
|
|
api_version = get_api_version(exec_files[0])
|
2008-03-13 22:57:24 +00:00
|
|
|
|
|
|
|
existing_versions = database.AppVersions.find(app=app, platform=platform, version_num=version_num, plan_class=plan_class)
|
|
|
|
if existing_versions:
|
|
|
|
if verbose:
|
|
|
|
print " Skipping existing %s %3d: %s" %(app.name, version_num, file_base)
|
|
|
|
return
|
|
|
|
|
|
|
|
print " Found %s version %s for %s: %s" %(app, version_num, platform, file_base),
|
|
|
|
if non_exec_files:
|
|
|
|
print "(+ %d bundled file(s))"%len(non_exec_files)
|
|
|
|
else:
|
|
|
|
print
|
|
|
|
|
|
|
|
xml_doc = tools.process_app_version(
|
|
|
|
app = app,
|
|
|
|
version_num = version_num,
|
|
|
|
exec_files = exec_files,
|
|
|
|
non_exec_files = non_exec_files,
|
|
|
|
signature_files = signature_files,
|
|
|
|
file_ref_infos = file_ref_infos,
|
2008-03-19 16:54:36 +00:00
|
|
|
api_version = api_version,
|
|
|
|
extra_xml = extra_xml
|
2008-03-13 22:57:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
object = database.AppVersion(
|
|
|
|
create_time = create_time,
|
|
|
|
app = app,
|
|
|
|
platform = platform,
|
|
|
|
version_num = version_num,
|
|
|
|
xml_doc = xml_doc,
|
|
|
|
plan_class = plan_class
|
|
|
|
)
|
2003-09-05 21:53:46 +00:00
|
|
|
|
2003-10-26 07:29:03 +00:00
|
|
|
objects_to_commit.append(object)
|
2003-09-05 21:53:46 +00:00
|
|
|
|
2004-10-29 18:18:53 +00:00
|
|
|
# Return a match if the filename is a possible exec file name (or installer)
|
|
|
|
|
2003-10-26 07:35:09 +00:00
|
|
|
def re_match_exec_filename(filepath):
|
|
|
|
file = os.path.basename(filepath)
|
2008-03-27 18:25:29 +00:00
|
|
|
return re.match('[^.]+_([0-9]+)[.]([0-9]+)_([^.]+?(?:[0-9][0-9.]*[0-9])?)(__[^.]+)?(?:[.]gz|[.]exe|[.]sit|[.]msi)?$', file)
|
2003-09-05 21:53:46 +00:00
|
|
|
|
2003-10-26 07:29:03 +00:00
|
|
|
def find_versions(app, dir):
|
2005-07-21 08:24:09 +00:00
|
|
|
"""Find application versions in DIR.
|
2008-03-19 16:54:36 +00:00
|
|
|
If directory contains sub-directories,
|
|
|
|
those are scanned (non-recursively) for files.
|
2003-10-26 07:29:03 +00:00
|
|
|
"""
|
2003-09-05 21:53:46 +00:00
|
|
|
|
2003-10-28 00:54:03 +00:00
|
|
|
for filepath in xlistdir(dir):
|
2004-10-29 18:18:53 +00:00
|
|
|
# ignore symlinks
|
2003-10-26 07:35:09 +00:00
|
|
|
if os.path.islink(filepath):
|
|
|
|
continue
|
2004-10-29 18:18:53 +00:00
|
|
|
|
|
|
|
# ignore signature files
|
|
|
|
if filepath.endswith('.sig'):
|
|
|
|
continue
|
|
|
|
|
|
|
|
# look for an executable file (proper .ext at end)
|
2004-06-24 12:13:42 +00:00
|
|
|
match = re_match_exec_filename(filepath)
|
|
|
|
if not match:
|
|
|
|
print >>sys.stderr, " Ignoring unknown file", filepath
|
|
|
|
continue
|
2003-10-26 07:29:03 +00:00
|
|
|
if os.path.isdir(filepath):
|
2004-06-24 12:13:42 +00:00
|
|
|
find_versions__process_bundle(app, match, filepath)
|
2003-10-26 07:29:03 +00:00
|
|
|
else:
|
2004-06-24 12:13:42 +00:00
|
|
|
find_versions__process_single_file(app, match, filepath)
|
2004-05-31 17:22:51 +00:00
|
|
|
|
2005-01-27 23:09:19 +00:00
|
|
|
# Process an app that is a single file only,
|
|
|
|
# possibly with a signature file included.
|
2004-10-29 18:18:53 +00:00
|
|
|
#
|
2004-06-24 12:13:42 +00:00
|
|
|
def find_versions__process_single_file(app, match, filepath):
|
2005-03-01 21:00:06 +00:00
|
|
|
'''add a single executable as app version'''
|
2004-10-29 18:18:53 +00:00
|
|
|
# Find signature file, if it exists.
|
|
|
|
signature_files={}
|
2005-03-01 21:00:06 +00:00
|
|
|
exec_files=[]
|
2004-10-29 18:18:53 +00:00
|
|
|
sig_file = filepath + ".sig"
|
|
|
|
if os.path.isfile(sig_file):
|
|
|
|
signature_files[filepath] = sig_file
|
2005-03-01 21:00:06 +00:00
|
|
|
exec_files.insert(0, filepath)
|
2004-10-29 18:18:53 +00:00
|
|
|
|
2005-01-27 22:29:06 +00:00
|
|
|
add_files(
|
|
|
|
app = app,
|
2005-03-01 21:00:06 +00:00
|
|
|
match = match,
|
|
|
|
exec_files = exec_files,
|
|
|
|
signature_files = signature_files,
|
2005-01-27 22:29:06 +00:00
|
|
|
)
|
2004-10-29 18:18:53 +00:00
|
|
|
|
|
|
|
|
2005-12-20 22:36:31 +00:00
|
|
|
# touch a file
|
|
|
|
|
|
|
|
def touch_file(fname):
|
|
|
|
'''touch a file'''
|
|
|
|
file_ptr = open(fname, 'w')
|
|
|
|
file_ptr.close()
|
|
|
|
|
2004-10-29 18:18:53 +00:00
|
|
|
# Process an app that is a bundle of files in a directory of the same name,
|
|
|
|
# possibly with signature files included.
|
|
|
|
|
2004-06-24 12:13:42 +00:00
|
|
|
def find_versions__process_bundle(app, match, dir):
|
2005-07-21 08:24:09 +00:00
|
|
|
'''add executable + bundle as app version'''
|
2005-01-27 23:09:19 +00:00
|
|
|
exec_files = []
|
2004-05-31 17:22:51 +00:00
|
|
|
non_exec_files = []
|
2004-05-31 17:57:18 +00:00
|
|
|
signature_files = {}
|
2004-09-14 22:24:58 +00:00
|
|
|
file_ref_infos = {}
|
2008-03-19 16:54:36 +00:00
|
|
|
extra_xml = ''
|
2004-06-24 12:13:42 +00:00
|
|
|
dirname = os.path.basename(dir)
|
2007-07-20 20:19:35 +00:00
|
|
|
found_main = False
|
2004-05-31 17:22:51 +00:00
|
|
|
for filepath in xlistdir(dir):
|
|
|
|
if os.path.isdir(filepath):
|
|
|
|
continue
|
2004-06-24 12:13:42 +00:00
|
|
|
if os.path.basename(filepath) == dirname:
|
2005-01-27 22:29:06 +00:00
|
|
|
# the filename matches the folder name,
|
|
|
|
# so this is the main program executable.
|
2005-01-27 23:09:19 +00:00
|
|
|
exec_files.insert(0, filepath)
|
2007-07-20 20:19:35 +00:00
|
|
|
found_main = True
|
2004-06-24 12:13:42 +00:00
|
|
|
continue
|
2004-05-31 17:57:18 +00:00
|
|
|
# if filename is of format 'EXECFILE.sig' treat it as signature file
|
|
|
|
if filepath.endswith('.sig'):
|
|
|
|
s = filepath[:-4]
|
2004-12-08 00:14:52 +00:00
|
|
|
signature_files[s] = filepath
|
|
|
|
continue
|
2008-03-19 16:54:36 +00:00
|
|
|
if os.path.basename(filepath) == 'extra_xml':
|
|
|
|
extra_xml = open(filepath).read()
|
|
|
|
continue
|
2004-08-18 21:53:19 +00:00
|
|
|
if filepath.endswith('.file_ref_info'):
|
|
|
|
s = filepath[:-len('.file_ref_info')]
|
|
|
|
file_ref_infos[s] = open(filepath).read()
|
|
|
|
continue
|
2005-01-27 23:09:19 +00:00
|
|
|
if os.access(filepath, os.X_OK):
|
|
|
|
exec_files.append(filepath)
|
|
|
|
continue;
|
2004-05-31 17:22:51 +00:00
|
|
|
non_exec_files.append(filepath)
|
2007-07-20 20:19:35 +00:00
|
|
|
if not found_main:
|
|
|
|
print >>sys.stderr, " Ignoring directory (no main program found - it has to be named the same as the directory)", dir
|
2004-05-31 17:29:31 +00:00
|
|
|
return
|
2005-01-27 23:09:19 +00:00
|
|
|
|
2004-08-18 21:53:19 +00:00
|
|
|
# check signatures, file_path_infos
|
|
|
|
for filepath, signature_file in signature_files.items():
|
2005-01-27 23:09:19 +00:00
|
|
|
if filepath not in exec_files and filepath not in non_exec_files:
|
|
|
|
print >>sys.stderr, " Warning: signature file '%s' will be ignored because it does not match a file" %signature_file
|
2004-08-18 21:53:19 +00:00
|
|
|
for filepath in file_ref_infos:
|
|
|
|
file_ref_info_filepath = filepath+'.file_ref_info'
|
2005-01-27 23:09:19 +00:00
|
|
|
if filepath not in exec_files and filepath not in non_exec_files:
|
2004-08-18 21:53:19 +00:00
|
|
|
print >>sys.stderr, " Warning: file_ref info file '%s' will be ignored because it does not match a file" %file_ref_info_filepath
|
|
|
|
|
2005-01-27 22:29:06 +00:00
|
|
|
add_files(
|
|
|
|
app = app,
|
|
|
|
match = match,
|
2005-01-27 23:09:19 +00:00
|
|
|
exec_files = exec_files,
|
2005-01-27 22:29:06 +00:00
|
|
|
non_exec_files = non_exec_files,
|
|
|
|
signature_files = signature_files,
|
|
|
|
file_ref_infos = file_ref_infos,
|
2008-03-19 16:54:36 +00:00
|
|
|
extra_xml = extra_xml,
|
2005-01-27 22:29:06 +00:00
|
|
|
)
|
2003-09-05 21:53:46 +00:00
|
|
|
|
2004-10-29 18:18:53 +00:00
|
|
|
####################
|
|
|
|
# BEGIN:
|
|
|
|
|
2003-10-28 00:54:03 +00:00
|
|
|
for appdir in xlistdir(config.app_dir):
|
2003-09-05 21:53:46 +00:00
|
|
|
if not os.path.isdir(appdir): continue
|
|
|
|
dirname = os.path.basename(appdir)
|
|
|
|
appname = os.path.basename(appdir)
|
|
|
|
apps = database.Apps.find(name=appname)
|
|
|
|
if apps:
|
2004-10-29 18:18:53 +00:00
|
|
|
if verbose:
|
|
|
|
print "Looking for %s versions in"%apps[0], appdir
|
2003-09-05 21:53:46 +00:00
|
|
|
find_versions(apps[0], appdir)
|
|
|
|
continue
|
|
|
|
|
|
|
|
print "Couldn't find app '%s'" %(appname)
|
|
|
|
|
|
|
|
if not objects_to_commit:
|
|
|
|
raise SystemExit("No new versions found!")
|
|
|
|
|
2003-10-28 00:55:33 +00:00
|
|
|
print "Ready to commit %d items:" %len(objects_to_commit)
|
2003-09-05 21:53:46 +00:00
|
|
|
for object in objects_to_commit:
|
|
|
|
print " ", object
|
|
|
|
|
2003-10-03 05:53:28 +00:00
|
|
|
if not tools.query_yesno("Continue"):
|
2003-09-05 21:53:46 +00:00
|
|
|
raise SystemExit
|
|
|
|
|
2003-10-28 00:54:30 +00:00
|
|
|
print "Committed:"
|
2003-09-05 21:53:46 +00:00
|
|
|
for object in objects_to_commit:
|
|
|
|
object.commit()
|
2003-10-28 00:54:30 +00:00
|
|
|
print " ", object
|
2003-09-05 21:53:46 +00:00
|
|
|
|
2006-11-03 21:42:49 +00:00
|
|
|
touch_file('reread_db')
|
2005-12-20 22:36:31 +00:00
|
|
|
print "Touched trigger file to make feeder re-read app_version table from database"
|
2003-09-05 21:53:46 +00:00
|
|
|
print "Done"
|