2003-07-25 22:15:12 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
2003-09-05 21:53:46 +00:00
|
|
|
"""
|
|
|
|
Scans apps dir for current core client and application versions 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/boinc/ contains core client versions.
|
|
|
|
apps/APPLICATION_NAME/ contains application versions for each application.
|
|
|
|
|
2003-10-26 07:44:14 +00:00
|
|
|
Filenames MUST be of the form NAME_VERSION_PLATFORM[.ext]. The prefix name
|
|
|
|
and extensions .gz, .exe, .sit are ignored. Platform strings must match the
|
|
|
|
names of platforms in the database.
|
2003-09-05 21:53:46 +00:00
|
|
|
|
2003-10-26 07:44:14 +00:00
|
|
|
update_versions also handles sub-directories, which contain files to bundle as
|
2003-10-26 07:47:33 +00:00
|
|
|
a single app-version. Sub-directory names are ignored. Non-executable files
|
|
|
|
can be arbitrarily named.
|
2003-10-26 07:44:14 +00:00
|
|
|
|
|
|
|
Example setup:
|
|
|
|
|
|
|
|
apps/boinc/boinc_7.17_i686-pc-linux-gnu.gz
|
|
|
|
apps/Astropulse/astropulse_7.17_windows_intelx86.exe
|
|
|
|
apps/SETI@home/sah_4.20_sparc-sun-solaris2.9.gz
|
2003-10-26 07:47:33 +00:00
|
|
|
apps/SETI@home/sah_4.20_i686-pc-linux-gnu.gz
|
2003-10-26 07:44:14 +00:00
|
|
|
apps/SETI@Home/sah_4.21_sparc-sun-solaris2.9/sah_4.21_sparc-sun-solaris2.9.gz
|
2003-10-26 07:50:05 +00:00
|
|
|
apps/SETI@Home/sah_4.21_sparc-sun-solaris2.9/sah_logo_1.0.jpg
|
2003-10-26 07:47:33 +00:00
|
|
|
apps/SETI@Home/sah_4.21_i686-pc-linux-gnu/sah_4.21_i686-pc-linux-gnu.gz
|
2003-10-26 07:50:05 +00:00
|
|
|
apps/SETI@Home/sah_4.21_i686-pc-linux-gnu/sah_logo_1.0.jpg
|
2003-09-05 21:53:46 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import boinc_path_config
|
|
|
|
from Boinc import database, db_mid, configxml, tools
|
2003-10-26 07:37:45 +00:00
|
|
|
import sys, os, re, time
|
2003-09-05 21:53:46 +00:00
|
|
|
|
2004-05-14 06:49:11 +00:00
|
|
|
def get_current_core_version():
|
|
|
|
cursor = database.get_dbconnection().cursor()
|
|
|
|
cursor.execute('select max(version_num) from core_version')
|
2004-06-08 20:28:26 +00:00
|
|
|
x = cursor.fetchall()[0].values()[0]
|
|
|
|
if x == None:
|
|
|
|
return 0
|
2004-05-24 20:32:51 +00:00
|
|
|
return int(cursor.fetchall()[0].values()[0])
|
2004-05-14 06:49:11 +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()
|
|
|
|
|
2004-05-24 20:32:51 +00:00
|
|
|
##### only allow most recent core client
|
|
|
|
if True:
|
|
|
|
min_core_version = get_current_core_version()
|
|
|
|
else:
|
|
|
|
min_core_version = 0
|
|
|
|
|
2003-09-05 21:53:46 +00:00
|
|
|
create_time = int(time.time())
|
|
|
|
|
|
|
|
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 = []
|
|
|
|
|
|
|
|
def xsort(list):
|
|
|
|
newlist = list[:]
|
|
|
|
newlist.sort()
|
|
|
|
return newlist
|
|
|
|
|
2003-10-28 00:54:03 +00:00
|
|
|
def xlistdir(dir):
|
|
|
|
return map(lambda file: os.path.join(dir, file), os.listdir(dir))
|
|
|
|
|
2004-05-31 17:57:18 +00:00
|
|
|
def add_files(app, match, exec_file, non_exec_files=[], signature_files={},
|
2004-05-14 06:49:11 +00:00
|
|
|
min_core_version = 0, max_core_version = 0):
|
2003-10-26 07:29:03 +00:00
|
|
|
''' add files to app/core.
|
|
|
|
|
|
|
|
EXEC_FILE is the executable, and NON_EXEC_FILES are supporting
|
|
|
|
non-executable files.
|
|
|
|
|
|
|
|
MATCH is the output of re_match_exec_filename(EXEC_FILE).
|
|
|
|
'''
|
|
|
|
assert(match)
|
2004-06-24 12:13:42 +00:00
|
|
|
assert(exec_file)
|
2003-10-26 07:29:03 +00:00
|
|
|
version_major, version_minor, platform_name = match.groups()
|
|
|
|
version_num = int(version_major) * 100 + int(version_minor)
|
|
|
|
|
|
|
|
file_base = os.path.basename(exec_file)
|
|
|
|
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
|
|
|
|
2003-10-26 07:29:03 +00:00
|
|
|
if app:
|
|
|
|
existing_versions = database.AppVersions.find(app=app, platform=platform, version_num=version_num)
|
|
|
|
if existing_versions:
|
|
|
|
if verbose:
|
|
|
|
print " Skipping existing %s %3d: %s" %(app.name, version_num, file_base)
|
2003-10-26 07:32:42 +00:00
|
|
|
return
|
2003-10-26 07:29:03 +00:00
|
|
|
|
|
|
|
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_file],
|
2004-05-31 17:57:18 +00:00
|
|
|
non_exec_files = non_exec_files,
|
|
|
|
signature_files = signature_files
|
2003-10-26 07:29:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
object = database.AppVersion(create_time = create_time,
|
|
|
|
app = app,
|
|
|
|
platform = platform,
|
|
|
|
version_num = version_num,
|
2004-05-14 06:49:11 +00:00
|
|
|
min_core_version = min_core_version,
|
|
|
|
max_core_version = max_core_version,
|
2003-10-26 07:29:03 +00:00
|
|
|
xml_doc = xml_doc)
|
|
|
|
else:
|
|
|
|
assert(not non_exec_files) # this wouldn't make sense for core clients
|
|
|
|
existing_versions = database.CoreVersions.find(platform=platform, version_num=version_num)
|
|
|
|
if existing_versions:
|
|
|
|
if verbose:
|
|
|
|
print " Skipping existing core version %s: %s" %(version_num, file_base)
|
2003-10-26 07:32:42 +00:00
|
|
|
return
|
2003-09-05 21:53:46 +00:00
|
|
|
|
2003-10-26 07:29:03 +00:00
|
|
|
print " Found core version %3d for %s: %s" %(version_num, platform, file_base)
|
2003-09-05 21:53:46 +00:00
|
|
|
|
2003-10-26 07:29:03 +00:00
|
|
|
xml_doc = tools.process_executable_file(exec_file)
|
2003-09-05 21:53:46 +00:00
|
|
|
|
2003-10-26 07:29:03 +00:00
|
|
|
object = database.CoreVersion(create_time = create_time,
|
|
|
|
platform = platform,
|
|
|
|
version_num = version_num,
|
|
|
|
xml_doc = xml_doc)
|
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
|
|
|
|
2003-10-26 07:35:09 +00:00
|
|
|
def re_match_exec_filename(filepath):
|
|
|
|
file = os.path.basename(filepath)
|
2004-04-01 23:31:58 +00:00
|
|
|
return re.match('[^.]+_([0-9]+)[.]([0-9]+)_([^.]+?(?:[0-9][0-9.]*[0-9])?)(?:[.]gz|[.]exe|[.]sit)?$', file)
|
2003-09-05 21:53:46 +00:00
|
|
|
|
2003-10-26 07:29:03 +00:00
|
|
|
def find_versions(app, dir):
|
|
|
|
"""Find application versions/core client versions in DIR.
|
2003-09-05 21:53:46 +00:00
|
|
|
|
2003-10-26 07:29:03 +00:00
|
|
|
if app==None, then dir contains core clients; else contains application
|
|
|
|
versions.
|
2003-09-05 21:53:46 +00:00
|
|
|
|
2003-10-26 07:29:03 +00:00
|
|
|
If directory contains sub-directories, those are scanned (non-recursively)
|
|
|
|
for files. If an executable is found, the first one found
|
|
|
|
(alphabetically) is the main program and other files bundled as
|
|
|
|
non-executables.
|
2003-09-05 21:53:46 +00:00
|
|
|
|
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):
|
2003-10-26 07:35:09 +00:00
|
|
|
if os.path.islink(filepath):
|
2004-05-31 17:22:51 +00:00
|
|
|
# ignore symlinks
|
2003-10-26 07:35:09 +00:00
|
|
|
continue
|
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
|
|
|
|
2004-06-24 12:13:42 +00:00
|
|
|
def find_versions__process_single_file(app, match, filepath):
|
2004-05-31 17:22:51 +00:00
|
|
|
'''add a single executable as app/core version'''
|
|
|
|
add_files(app=app, match=match, exec_file=filepath,
|
|
|
|
min_core_version = min_core_version
|
|
|
|
)
|
|
|
|
|
2004-06-24 12:13:42 +00:00
|
|
|
def find_versions__process_bundle(app, match, dir):
|
2004-05-31 17:22:51 +00:00
|
|
|
'''add executable + bundle as app/core version'''
|
|
|
|
exec_file = None
|
|
|
|
non_exec_files = []
|
2004-05-31 17:57:18 +00:00
|
|
|
signature_files = {}
|
2004-06-24 12:13:42 +00:00
|
|
|
dirname = os.path.basename(dir)
|
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:
|
|
|
|
# the filename matches the folder name, so this is the executable.
|
|
|
|
exec_file = filepath
|
|
|
|
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]
|
|
|
|
if re_match_exec_filename(s):
|
|
|
|
signature_files[s] = filepath
|
|
|
|
continue
|
2004-05-31 17:22:51 +00:00
|
|
|
non_exec_files.append(filepath)
|
2004-06-24 12:22:30 +00:00
|
|
|
if not exec_file:
|
|
|
|
print >>sys.stderr, " Ignoring directory (no executable found - it has to be named the same as the directory)", dir
|
2004-05-31 17:29:31 +00:00
|
|
|
return
|
2004-05-31 17:57:18 +00:00
|
|
|
add_files(app = app,
|
|
|
|
match = match,
|
|
|
|
exec_file = exec_file,
|
|
|
|
non_exec_files = non_exec_files,
|
|
|
|
signature_files = signature_files,
|
2004-05-31 17:22:51 +00:00
|
|
|
min_core_version = min_core_version
|
|
|
|
)
|
2003-09-05 21:53:46 +00:00
|
|
|
|
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)
|
|
|
|
if dirname == 'boinc':
|
|
|
|
print "Looking for core versions in", appdir
|
|
|
|
find_versions(None, appdir)
|
|
|
|
continue
|
|
|
|
appname = os.path.basename(appdir)
|
|
|
|
apps = database.Apps.find(name=appname)
|
|
|
|
if apps:
|
|
|
|
print "Looking for %s versions in"%apps[0], appdir
|
|
|
|
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
|
|
|
|
|
|
|
print "Done"
|