mirror of https://github.com/BOINC/boinc.git
136 lines
4.3 KiB
Python
Executable File
136 lines
4.3 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
# $Id$
|
|
|
|
"""
|
|
Scans apps dir for current core client and application versions and updates
|
|
the database as appropriate.
|
|
|
|
config.xml must contain an <app_dir> which specifies the directory to search.
|
|
|
|
apps/boinc/ contains core client versions.
|
|
apps/APPLICATION_NAME/ contains application versions for each application.
|
|
|
|
file names must be of the form NAME_VERSION_PLATFORM[.ext]:
|
|
boinc_7.17_i686-pc-linux-gnu.gz
|
|
astropulse_7.17_windows_intelx86.exe
|
|
|
|
The prefix name and extensions .gz, .exe, .sit are ignored. Platform strings
|
|
must match the names of platforms in the database.
|
|
|
|
"""
|
|
|
|
import boinc_path_config
|
|
from Boinc import database, db_mid, configxml, tools
|
|
import sys, os, glob, re, time
|
|
|
|
config = configxml.default_config().config
|
|
database.connect()
|
|
|
|
create_time = int(time.time())
|
|
|
|
assert(config.app_dir
|
|
and
|
|
config.download_dir
|
|
and
|
|
config.download_url
|
|
)
|
|
|
|
objects_to_commit = []
|
|
|
|
def xsort(list):
|
|
newlist = list[:]
|
|
newlist.sort()
|
|
return newlist
|
|
|
|
def find_versions(app, dir):
|
|
"""Find application versions/core client versions in DIR.
|
|
|
|
if app==None, then dir contains core clients; else contains application
|
|
versions for core client."""
|
|
|
|
for filepath in xsort(glob.glob(os.path.join(appdir, '*'))):
|
|
file = os.path.basename(filepath)
|
|
filepath = os.path.join(dir,file)
|
|
if os.path.isdir(filepath):
|
|
continue
|
|
match = re.match('[^.]+_([0-9]+)[.]([0-9]+)_(.+?)(?:[.]gz|[.]exe|[.]sit)?$', file)
|
|
if not match:
|
|
print >>sys.stderr, " Ignoring unknown file", os.path.join(filepath)
|
|
continue
|
|
|
|
version_major, version_minor, platform_name = match.groups()
|
|
version_num = int(version_major) * 100 + int(version_minor)
|
|
|
|
platforms = database.Platforms.find(name = platform_name)
|
|
if not platforms:
|
|
print >>sys.stderr, " Unknown platform '%s' for file %s" %(platform_name, file)
|
|
continue
|
|
platform = platforms[0]
|
|
|
|
if app:
|
|
existing_versions = database.AppVersions.find(app=app, platform=platform, version_num=version_num)
|
|
if existing_versions:
|
|
print " Skipping existing %s %3d: %s" %(app.name, version_num, file)
|
|
continue
|
|
|
|
print " Found %s version %s for %s: %s" %(app, version_num, platform, file)
|
|
|
|
xml_doc = tools.process_app_version(
|
|
app = app,
|
|
version_num = version_num,
|
|
exec_files = [filepath])
|
|
|
|
object = database.AppVersion(create_time = create_time,
|
|
app = app,
|
|
platform = platform,
|
|
version_num = version_num,
|
|
xml_doc = xml_doc)
|
|
else:
|
|
existing_versions = database.CoreVersions.find(platform=platform, version_num=version_num)
|
|
if existing_versions:
|
|
print " Skipping existing core version %s: %s" %(version_num, file)
|
|
continue
|
|
|
|
print " Found core version %3d for %s: %s" %(version_num, platform, file)
|
|
|
|
xml_doc = tools.process_executable_file(filepath)
|
|
|
|
object = database.CoreVersion(create_time = create_time,
|
|
platform = platform,
|
|
version_num = version_num,
|
|
xml_doc = xml_doc)
|
|
|
|
objects_to_commit.append(object)
|
|
|
|
for appdir in xsort(glob.glob(os.path.join(config.app_dir,'*'))):
|
|
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!")
|
|
|
|
print "Commit %d items:" %len(objects_to_commit)
|
|
for object in objects_to_commit:
|
|
print " ", object
|
|
|
|
if not tools.query_yesno("Continue"):
|
|
raise SystemExit
|
|
|
|
for object in objects_to_commit:
|
|
object.commit()
|
|
|
|
print "Done"
|