2003-07-25 22:15:12 +00:00
#!/usr/bin/env python
# $Id$
2003-08-01 23:04:58 +00:00
# Scans apps dir for current core client and application versions and updates
# the database as appropriate.
2003-08-22 23:40:15 +00:00
try:
2003-08-31 00:18:45 +00:00
from versions_config import *
2003-08-22 23:40:15 +00:00
except ImportError:
raise SystemExit("""
Couldn't import versions_config. You must create this file. See
tools/versions_config.py.sample.
""")
2003-08-01 23:04:58 +00:00
class Project:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
2003-07-25 22:15:12 +00:00
2003-08-31 00:18:45 +00:00
# DUPLICATE_PLATFORM_EXECUTABLES = {'sparc-sun-solaris2.8':'sparc-sun-solaris2.7'}
2003-07-25 22:15:12 +00:00
2003-08-01 23:04:58 +00:00
BoincCoreApp = Project(appname='BOINC Core Client')
# Note: treat Darwin (CLI) as Unix (independent of MacOSX GUI)
platform_name_windows = 'windows_intelx86'
platform_name_macosx = 'MacOSX'
2003-07-25 22:15:12 +00:00
import sys, os, glob, re
def get_download_dir(directory_name): return os.path.join(PROJECTS_ROOT,directory_name,'download')
def get_download_url(url_name): return os.path.join(URL_ROOT,url_name,'download')
program_path = os.path.realpath(os.path.dirname(sys.argv[0]))
sys.path[0:0] = ['../py', os.path.realpath(os.path.join(program_path, '../py'))]
def xsort(list):
newlist = list[:]
newlist.sort()
return newlist
def query_yesno(msg):
'''Query y/n; default Y'''
print msg, "[Y/n]? ",
return not raw_input().lower().startswith('n')
2003-08-31 00:18:45 +00:00
# def map_dupes(dict):
# for (platform_name,target_platform_name) in DUPLICATE_PLATFORM_EXECUTABLES.items():
# if target_platform_name in dict and not platform_name in dict:
# dict[platform_name] = dict[target_platform_name]
2003-08-01 23:04:58 +00:00
def glob_app(pattern):
return pattern and glob.glob(os.path.join(APPS_DIR,pattern)) or []
# unix_pattern can include others also
def get_clients(app, unix_pattern, windows_pattern='', mac_pattern=''):
unix_clients, windows_clients, mac_clients = \
map(glob_app, [unix_pattern, windows_pattern, mac_pattern])
2003-08-31 00:18:45 +00:00
client_list = []
2003-08-01 23:04:58 +00:00
for client in windows_clients:
2003-08-31 00:18:45 +00:00
client_list.append( (platform_name_windows,
get_version(client),
client) )
2003-08-01 23:04:58 +00:00
for client in mac_clients:
2003-08-31 00:18:45 +00:00
client_list.append( (platform_name_macosx,
get_version(client),
client) )
2003-08-01 23:04:58 +00:00
for client in unix_clients:
platform_name = re.sub('.*_','',client).replace('.gz','').replace('.exe','')
if platform_name == 'win':
platform_name = platform_name_windows
elif platform_name == 'os_x':
platform_name = platform_name_macosx
2003-08-31 00:18:45 +00:00
client_list.append( (platform_name_windows,
get_version(client),
client) )
app.clients = client_list
2003-08-01 23:04:58 +00:00
show_clients(app)
def show_clients(app):
2003-08-31 00:18:45 +00:00
if not app.clients:
2003-08-01 23:04:58 +00:00
print "No clients found for", app.appname, "version %s in %s!"%(version_string,APPS_DIR)
return
print "Clients found for", app.appname, "version", version_string, ":"
2003-08-31 00:18:45 +00:00
for client in app.clients:
print ' ', client[0].ljust(20), client[1], client[2]
2003-08-01 23:04:58 +00:00
2003-08-22 23:40:15 +00:00
def get_version(exec_name):
m = re.search('([0-9]+)[.]([0-9]+)', exec_name)
if not m:
raise SystemExit("Couldn't find version number in executable '%s'"%exec_name)
return int(m.group(1))*100 + int(m.group(2))
2003-07-25 22:15:12 +00:00
tried_apps_dirs = [ APPS_DIR ]
if not os.path.isdir(APPS_DIR):
APPS_DIR = os.path.join(program_path, APPS_DIR)
tried_apps_dirs.append(APPS_DIR)
if not os.path.isdir(APPS_DIR):
raise SystemExit("Couldn't find apps dir in %s"%tried_apps_dirs)
APPS_DIR = os.path.realpath(APPS_DIR)
PROJECTS_ROOT = os.path.realpath(os.path.expanduser(PROJECTS_ROOT))
KEY_DIR = os.path.realpath(os.path.expanduser(KEY_DIR))
2003-08-31 00:18:45 +00:00
# version_num = MAJOR_VERSION * 100 + MINOR_VERSION
# version_string = "%d.%02d"%(MAJOR_VERSION, MINOR_VERSION)
2003-07-25 22:15:12 +00:00
2003-08-01 23:04:58 +00:00
get_clients(BoincCoreApp,
unix_pattern='boinc_'+version_string+'*.gz',
windows_pattern='BOINC_'+version_string+'*.exe',
mac_pattern='boinc_'+version_string+'*.sit')
for project in PROJECTS:
for app in project.applications:
2003-08-22 23:40:15 +00:00
get_clients(app, app.exe_prefix+'*')
2003-08-01 23:04:58 +00:00
for project in PROJECTS:
directory_name = project.directory_name
db_name = project.db_name
url_name = project.url_name
2003-07-25 22:15:12 +00:00
print "--- database", db_name, " ---"
existing_count = int(os.popen("""echo 'select count(*) from core_version where version_num=%d'|mysql %s"""%(version_num, db_name)).readlines()[-1].strip() or 0)
if existing_count:
if not query_yesno(" Delete %d existing version %s clients?"%(existing_count, version_string)):
print " Skipping", db_name
continue
print " Deleting from core_version"
os.system("""echo 'delete from core_version where version_num=%d' | mysql %s"""%(version_num, db_name))
code_sign_file = os.path.join(KEY_DIR, 'code_sign_private')
2003-08-01 23:04:58 +00:00
client_map = BoincCoreApp.client_versions
2003-07-25 22:15:12 +00:00
for platform_name in xsort(client_map.keys()):
exec_file = os.path.split(client_map[platform_name])[1]
download_dir = get_download_dir(directory_name)
download_url = get_download_url(url_name)
print " Adding ", platform_name.ljust(20), os.path.join(download_dir,exec_file)
os.system("""
2003-08-01 23:04:59 +00:00
add core_version -db_name %(db_name)s \
2003-07-25 22:15:12 +00:00
-app_name 'core client' \
-platform_name %(platform_name)s \
-download_dir %(download_dir)s \
-download_url %(download_url)s \
-code_sign_keyfile %(code_sign_file)s \
-exec_dir %(APPS_DIR)s \
-version %(version_num)d \
-exec_files %(exec_file)s
""" %locals())
2003-08-01 23:04:58 +00:00
for app in project.applications:
appname = app.appname
2003-08-01 23:12:16 +00:00
print ' --- Application', appname, ' ---'
2003-08-01 23:04:58 +00:00
client_map = app.client_versions
for platform_name in xsort(client_map.keys()):
exec_file = os.path.split(client_map[platform_name])[1]
2003-08-22 23:40:15 +00:00
a_version_num = get_version(exec_file)
2003-08-01 23:04:58 +00:00
download_dir = get_download_dir(directory_name)
download_url = get_download_url(url_name)
2003-08-22 23:40:15 +00:00
print " Adding ", platform_name.ljust(20), a_version_num, os.path.join(download_dir,exec_file)
2003-08-01 23:04:58 +00:00
os.system("""
2003-08-01 23:09:44 +00:00
add app_version -db_name %(db_name)s \
2003-08-01 23:04:58 +00:00
-app_name '%(appname)s' \
-platform_name %(platform_name)s \
-download_dir %(download_dir)s \
-download_url %(download_url)s \
-code_sign_keyfile %(code_sign_file)s \
-exec_dir %(APPS_DIR)s \
2003-08-22 23:40:15 +00:00
-version %(a_version_num)d \
2003-08-01 23:04:58 +00:00
-exec_files %(exec_file)s
""" %locals())