2003-07-18 21:43:12 +00:00
|
|
|
## $Id$
|
|
|
|
|
2003-09-04 07:16:15 +00:00
|
|
|
# module for setting up a new project (either a real project or a test project
|
2003-10-03 05:53:28 +00:00
|
|
|
# see tools/makeproject, test/testbase.py).
|
2003-09-04 07:16:15 +00:00
|
|
|
|
2003-10-03 05:53:28 +00:00
|
|
|
# TODO: make sure things work if build_dir != src_dir
|
2003-09-04 07:16:14 +00:00
|
|
|
|
2003-09-04 05:54:55 +00:00
|
|
|
import boinc_path_config
|
2003-09-07 08:01:14 +00:00
|
|
|
from Boinc import database, db_mid, configxml, tools
|
|
|
|
from Boinc.boinc_db import *
|
2003-12-31 23:09:21 +00:00
|
|
|
import os, sys, glob, time, shutil, re, random, socket
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
class Options:
|
|
|
|
pass
|
|
|
|
|
|
|
|
options = Options()
|
|
|
|
errors = Options()
|
|
|
|
errors.count = 0
|
|
|
|
|
|
|
|
options.have_init = False
|
|
|
|
options.install_method = None
|
|
|
|
options.echo_verbose = 1
|
|
|
|
options.is_test = False
|
2003-07-18 23:20:46 +00:00
|
|
|
options.drop_db_first = False
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
def init():
|
|
|
|
if options.have_init: return
|
|
|
|
options.have_init = True
|
|
|
|
options.tty = os.isatty(1)
|
|
|
|
options.echo_overwrite = options.tty and options.echo_verbose==1
|
|
|
|
|
|
|
|
# VERBOSE: 0 = print nothing
|
|
|
|
# 1 = print some (default
|
|
|
|
# if output is a tty, overwrite lines.
|
|
|
|
# 2 = print all
|
|
|
|
|
|
|
|
if options.install_method == 'copy':
|
|
|
|
options.install_function = shutil.copy
|
|
|
|
elif options.install_method == 'link' or options.install_method == 'hardlink':
|
|
|
|
options.install_function = my_link
|
|
|
|
elif options.install_method == 'symlink' or options.install_method == 'softlink':
|
|
|
|
options.install_function = my_symlink
|
|
|
|
else:
|
|
|
|
fatal_error("Invalid install method: %s"%options.install_method)
|
|
|
|
|
|
|
|
prev_overwrite = False
|
|
|
|
def verbose_echo(level, line):
|
|
|
|
global prev_overwrite
|
|
|
|
if level == 0:
|
|
|
|
if prev_overwrite:
|
|
|
|
print
|
|
|
|
print line
|
|
|
|
prev_overwrite = False
|
|
|
|
elif options.echo_verbose >= level:
|
|
|
|
if options.echo_overwrite:
|
|
|
|
print "\r ",
|
|
|
|
print "\r", line,
|
|
|
|
sys.stdout.flush()
|
|
|
|
prev_overwrite = True
|
|
|
|
else:
|
|
|
|
print line
|
|
|
|
|
|
|
|
def fatal_error(msg):
|
|
|
|
errors.count += 1
|
|
|
|
verbose_echo(0, "FATAL ERROR: "+msg)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def error(msg, fatal=0):
|
|
|
|
if fatal: fatal_error(msg)
|
|
|
|
errors.count += 1
|
|
|
|
verbose_echo(0, "ERROR: "+msg)
|
|
|
|
|
|
|
|
def verbose_sleep(msg, wait):
|
|
|
|
front = msg + ' [sleep '
|
|
|
|
back = ']'
|
|
|
|
for i in range(1,wait+1):
|
|
|
|
verbose_echo(1, msg + ' [sleep ' + ('.'*i).ljust(wait) + ']')
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
def get_env_var(name, default = None):
|
|
|
|
value = os.environ.get(name, default)
|
|
|
|
if value == None:
|
|
|
|
print "Environment variable %s not defined" % name
|
|
|
|
sys.exit(1)
|
|
|
|
return value
|
|
|
|
|
|
|
|
def shell_call(cmd, doexec=False, failok=False):
|
|
|
|
if doexec:
|
|
|
|
os.execl('/bin/sh', 'sh', '-c', cmd)
|
|
|
|
error("Command failed: "+cmd, fatal=(not failok))
|
|
|
|
os._exit(1)
|
|
|
|
if os.system(cmd):
|
|
|
|
error("Command failed: "+cmd, fatal=(not failok))
|
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def verbose_shell_call(cmd, doexec=False, failok=False):
|
|
|
|
verbose_echo(2, " "+cmd)
|
|
|
|
return shell_call(cmd, doexec, failok)
|
|
|
|
|
|
|
|
def destpath(src,dest):
|
|
|
|
if dest.endswith('/'):
|
|
|
|
return dest + os.path.basename(src)
|
|
|
|
else:
|
|
|
|
return dest
|
|
|
|
|
|
|
|
# my_symlink and my_link just add the filename to the exception object if one
|
|
|
|
# is raised - don't know why it's not already there
|
|
|
|
def my_symlink(src,dest):
|
|
|
|
dest = destpath(src,dest)
|
|
|
|
try:
|
|
|
|
os.symlink(src,dest)
|
|
|
|
except OSError, e:
|
2003-07-25 20:26:38 +00:00
|
|
|
e.filename = src + ' -> ' + dest
|
2003-07-18 21:43:12 +00:00
|
|
|
raise
|
|
|
|
|
|
|
|
def my_link(src,dest):
|
|
|
|
dest = destpath(src,dest)
|
|
|
|
try:
|
|
|
|
os.link(src,dest)
|
|
|
|
except OSError, e:
|
2003-07-25 20:26:38 +00:00
|
|
|
e.filename = src + ' -> ' + dest
|
2003-07-18 21:43:12 +00:00
|
|
|
raise
|
|
|
|
|
|
|
|
# install = options.install_function
|
2004-06-04 13:26:46 +00:00
|
|
|
def install(src, dest, unless_exists=False):
|
|
|
|
if unless_exists and os.path.exists(dest):
|
|
|
|
return
|
2003-07-18 21:43:12 +00:00
|
|
|
options.install_function(src, dest)
|
|
|
|
|
|
|
|
def install_glob(glob_source, dest, failok=False):
|
|
|
|
dest = os.path.join(dest, '') # append '/' if necessary
|
|
|
|
for src in glob.glob(glob_source):
|
|
|
|
if not os.path.isdir(src):
|
|
|
|
install(src, dest)
|
|
|
|
|
|
|
|
def macro_substitute(macro, replacement, infile, outfile):
|
|
|
|
open(outfile, 'w').write(open(infile).read().replace(macro, replacement))
|
|
|
|
def macro_substitute_inplace(macro, replacement, inoutfile):
|
|
|
|
old = inoutfile + '.old'
|
|
|
|
os.rename(inoutfile, old)
|
|
|
|
macro_substitute(macro, replacement, old, inoutfile)
|
|
|
|
|
|
|
|
def check_program_exists(prog):
|
|
|
|
if not os.path.isfile(prog):
|
|
|
|
fatal_error("""
|
|
|
|
Executable not found: %s
|
|
|
|
Did you `make' yet?
|
|
|
|
""" % prog)
|
|
|
|
def check_core_client_executable():
|
2003-09-04 05:07:17 +00:00
|
|
|
check_program_exists(builddir('client', version.CLIENT_BIN_FILENAME))
|
2003-07-18 21:43:12 +00:00
|
|
|
def check_app_executable(app):
|
|
|
|
check_program_exists(builddir('apps', app))
|
|
|
|
|
|
|
|
def make_executable(name):
|
|
|
|
os.chmod(name, 755)
|
|
|
|
def force_symlink(src, dest):
|
|
|
|
if os.path.exists(dest):
|
|
|
|
os.unlink(dest)
|
|
|
|
my_symlink(src, dest)
|
|
|
|
def rmtree(dir):
|
2003-10-03 05:53:28 +00:00
|
|
|
# if os.path.exists(dir):
|
|
|
|
# shutil.rmtree(dir)
|
|
|
|
if not dir or dir == '/' or dir == '.' or ' ' in dir:
|
|
|
|
raise Exception
|
|
|
|
os.system("rm -rf %s"%dir)
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
def _remove_trail(s, suffix):
|
|
|
|
if s.endswith(suffix):
|
|
|
|
return s[:-len(suffix)]
|
|
|
|
else:
|
|
|
|
return s
|
|
|
|
|
|
|
|
def _url_to_filename(url):
|
2003-08-26 19:26:23 +00:00
|
|
|
s=""
|
|
|
|
for c in url.replace('http://',''):
|
2005-02-15 20:50:28 +00:00
|
|
|
if (c.isalnum()):
|
|
|
|
s += c
|
|
|
|
else:
|
|
|
|
s += '_'
|
2003-08-26 19:26:23 +00:00
|
|
|
return _remove_trail(s,'_')
|
|
|
|
|
2003-07-18 21:43:12 +00:00
|
|
|
def account_file_name(url):
|
|
|
|
return 'account_' + _url_to_filename(url) + '.xml'
|
|
|
|
|
|
|
|
def srcdir(*dirs):
|
2003-09-04 05:54:55 +00:00
|
|
|
return apply(os.path.join,(boinc_path_config.TOP_SOURCE_DIR,)+dirs)
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
def builddir(*dirs):
|
2003-09-04 05:54:55 +00:00
|
|
|
return apply(os.path.join,(boinc_path_config.TOP_BUILD_DIR,)+dirs)
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
def run_tool(cmd):
|
|
|
|
verbose_shell_call(builddir('tools', cmd))
|
|
|
|
|
|
|
|
def _gen_key_p(private_key, public_key):
|
|
|
|
shell_call("%s/crypt_prog -genkey 1024 %s %s >/dev/null" % (
|
|
|
|
builddir('lib'),
|
|
|
|
private_key,
|
|
|
|
public_key))
|
|
|
|
def _gen_key(key):
|
|
|
|
_gen_key_p(key+'_private', key+'_public')
|
|
|
|
|
|
|
|
def get_int(s):
|
|
|
|
'''Convert a string to an int; return 0 on error.'''
|
2003-08-18 22:34:53 +00:00
|
|
|
try: return int(s)
|
2003-07-18 21:43:12 +00:00
|
|
|
except: return 0
|
|
|
|
|
|
|
|
def unique(list):
|
|
|
|
d = {}
|
|
|
|
for i in list:
|
|
|
|
d[i] = 1
|
|
|
|
return d.keys()
|
|
|
|
|
|
|
|
def map_xml(dic, keys):
|
|
|
|
if not isinstance(dic,dict):
|
|
|
|
dic = dic.__dict__
|
|
|
|
s = ''
|
|
|
|
for key in keys:
|
|
|
|
s += "<%s>%s</%s>\n" % (key, dic[key], key)
|
|
|
|
return s[:-1]
|
|
|
|
|
|
|
|
def generate_shmem_key():
|
|
|
|
return '0x1111%x' % random.randrange(0,2**16)
|
|
|
|
|
|
|
|
def _check_vars(dict, **names):
|
|
|
|
for key in names:
|
|
|
|
value = names[key]
|
|
|
|
if not key in dict:
|
|
|
|
if value == None:
|
|
|
|
raise SystemExit('error in test script: required parameter "%s" not specified'%key)
|
|
|
|
dict[key] = value
|
|
|
|
for key in dict:
|
|
|
|
if not key in names:
|
|
|
|
raise SystemExit('error in test script: extraneous parameter "%s" unknown'%key)
|
|
|
|
|
2003-09-22 23:55:39 +00:00
|
|
|
# def db_query(db, query):
|
|
|
|
# db.query(query)
|
|
|
|
# result = db.use_result()
|
|
|
|
# return result and result.fetch_row(0,1)
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2003-10-03 05:53:28 +00:00
|
|
|
def num_results():
|
2003-09-22 23:55:39 +00:00
|
|
|
return database.Results.count()
|
2003-10-03 05:53:28 +00:00
|
|
|
def num_results_unsent():
|
2003-09-22 23:55:39 +00:00
|
|
|
return database.Results.count(server_state = RESULT_SERVER_STATE_UNSENT)
|
2003-10-03 05:53:28 +00:00
|
|
|
def num_results_in_progress():
|
2003-09-22 23:55:39 +00:00
|
|
|
return database.Results.count(server_state = RESULT_SERVER_STATE_IN_PROGRESS)
|
2003-10-03 05:53:28 +00:00
|
|
|
def num_results_over():
|
2003-09-22 23:55:39 +00:00
|
|
|
return database.Results.count(server_state = RESULT_SERVER_STATE_OVER)
|
2003-10-03 05:53:28 +00:00
|
|
|
def num_wus():
|
2003-09-22 23:55:39 +00:00
|
|
|
return database.Workunits.count()
|
2003-10-03 05:53:28 +00:00
|
|
|
def num_wus_assimilated():
|
2003-09-22 23:55:39 +00:00
|
|
|
return database.Workunits.count(assimilate_state = ASSIMILATE_DONE)
|
2003-10-03 05:53:28 +00:00
|
|
|
def num_wus_to_transition():
|
2003-10-03 06:46:22 +00:00
|
|
|
return database.Workunits.count(_extra_params = ['transition_time<%d'%(time.time()+30*86400)])
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2003-08-15 23:04:36 +00:00
|
|
|
def build_command_line(cmd, **kwargs):
|
|
|
|
for (key, value) in kwargs.items():
|
|
|
|
cmd += " -%s '%s'" %(key,value)
|
|
|
|
return cmd
|
|
|
|
|
2005-02-15 20:50:28 +00:00
|
|
|
def create_project_dirs(dest_dir):
|
|
|
|
def dir(*d):
|
|
|
|
return apply(os.path.join,(dest_dir,)+d)
|
|
|
|
def mkdir2(d):
|
|
|
|
try:
|
|
|
|
os.mkdir(d);
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
map(lambda d: mkdir2(dir(d)),
|
|
|
|
[ '',
|
|
|
|
'cgi-bin',
|
|
|
|
'bin',
|
|
|
|
'templates',
|
|
|
|
'upload',
|
|
|
|
'download',
|
|
|
|
'apps',
|
|
|
|
'html',
|
|
|
|
'html/cache',
|
|
|
|
'html/inc',
|
|
|
|
'html/languages',
|
|
|
|
'html/languages/compiled',
|
|
|
|
'html/languages/translations',
|
2005-02-17 20:35:41 +00:00
|
|
|
'html/languages/project_specific_translations',
|
2005-02-15 20:50:28 +00:00
|
|
|
'html/ops',
|
|
|
|
'html/project',
|
|
|
|
'html/stats',
|
|
|
|
'html/user',
|
|
|
|
'html/user_profile',
|
|
|
|
'html/user_profile/images'
|
|
|
|
])
|
|
|
|
|
|
|
|
# make directories writeable to Apache.
|
|
|
|
# make the CGI writeable in case scheduler writes req/reply files
|
|
|
|
# TODO: that is a security risk; don't do this in the future - write
|
|
|
|
# req/reply files somewhere else
|
|
|
|
#
|
|
|
|
map(lambda d: os.chmod(dir(d), 0777),
|
|
|
|
[
|
|
|
|
'cgi-bin',
|
|
|
|
'upload',
|
|
|
|
'html/cache',
|
|
|
|
'html/languages',
|
|
|
|
'html/languages/compiled',
|
|
|
|
'html/user_profile/images'
|
|
|
|
])
|
|
|
|
|
2003-10-03 05:53:28 +00:00
|
|
|
def install_boinc_files(dest_dir):
|
|
|
|
def dir(*dirs):
|
|
|
|
return apply(os.path.join,(dest_dir,)+dirs)
|
|
|
|
|
2005-02-15 20:50:28 +00:00
|
|
|
create_project_dirs(dest_dir);
|
|
|
|
|
2004-02-04 01:21:51 +00:00
|
|
|
install_glob(srcdir('html/inc/*.inc'), dir('html/inc/'))
|
2004-02-10 00:11:44 +00:00
|
|
|
install_glob(srcdir('html/inc/*.php'), dir('html/inc/'))
|
2004-06-10 19:43:54 +00:00
|
|
|
install_glob(srcdir('html/inc/*.dat'), dir('html/inc/'))
|
2004-02-04 01:21:51 +00:00
|
|
|
install_glob(srcdir('html/ops/*.php'), dir('html/ops/'))
|
|
|
|
install_glob(srcdir('html/ops/*.inc'), dir('html/ops/'))
|
|
|
|
install_glob(srcdir('html/user/*.php'), dir('html/user/'))
|
|
|
|
install_glob(srcdir('html/user/*.inc'), dir('html/user/'))
|
|
|
|
install_glob(srcdir('html/user/*.css'), dir('html/user/'))
|
|
|
|
install_glob(srcdir('html/user/*.txt'), dir('html/user/'))
|
2004-07-21 22:19:21 +00:00
|
|
|
install_glob(srcdir('html/user/*.png'), dir('html/user/'))
|
2005-02-08 22:07:40 +00:00
|
|
|
install_glob(srcdir('html/languages/translations/*.po'), dir('html/languages/translations/'))
|
2005-02-17 20:35:41 +00:00
|
|
|
install_glob(srcdir('html/languages/project_specific_translations/*.po'), dir('html/languages/project_specific_translations/'))
|
2003-10-03 05:53:28 +00:00
|
|
|
|
|
|
|
# copy all the backend programs
|
|
|
|
map(lambda (s): install(builddir('sched',s), dir('cgi-bin',s)),
|
|
|
|
[ 'cgi', 'file_upload_handler'])
|
|
|
|
map(lambda (s): install(builddir('sched',s), dir('bin',s)),
|
2004-07-13 13:54:09 +00:00
|
|
|
[ 'make_work', 'feeder', 'transitioner',
|
|
|
|
'sample_bitwise_validator', 'sample_trivial_validator',
|
|
|
|
'file_deleter', 'sample_dummy_assimilator',
|
2004-12-27 21:14:18 +00:00
|
|
|
'update_stats', 'db_dump', 'db_purge' ])
|
2003-10-03 05:53:28 +00:00
|
|
|
map(lambda (s): install(srcdir('sched',s), dir('bin',s)),
|
2004-12-06 22:41:19 +00:00
|
|
|
[ 'start', 'show_shmem' ])
|
2004-11-24 07:17:46 +00:00
|
|
|
force_symlink(dir('bin', 'start'), dir('bin', 'stop'))
|
|
|
|
force_symlink(dir('bin', 'start'), dir('bin', 'status'))
|
2003-10-03 05:53:28 +00:00
|
|
|
map(lambda (s): install(srcdir('tools',s), dir('bin',s)),
|
2004-11-24 07:17:46 +00:00
|
|
|
[ 'create_work', 'add', 'xadd', 'dbcheck_files_exist',
|
2004-11-24 19:17:50 +00:00
|
|
|
'update_versions', 'parse_config', 'grep_logs', 'db_query',
|
2004-12-06 22:41:19 +00:00
|
|
|
'watch_tcp', 'sign_executable', 'dir_hier_move', 'dir_hier_path' ])
|
2004-11-24 07:17:46 +00:00
|
|
|
map(lambda (s): install(srcdir('py/Boinc',s), dir('bin',s)),
|
|
|
|
[ 'add_util.py', 'boinc_db.py', 'boinc_project_path.py',
|
|
|
|
'boincxml.py', 'configxml.py', 'database.py',
|
|
|
|
'db_base.py', 'db_mid.py', 'projectxml.py',
|
|
|
|
'sched_messages.py', 'tools.py', 'util.py', 'version.py' ])
|
2004-12-08 00:14:52 +00:00
|
|
|
install(
|
|
|
|
srcdir('html/user', 'forum_sample_index.php'),
|
|
|
|
dir('html/user', 'forum_index.php'))
|
|
|
|
install(
|
|
|
|
srcdir('html/user', 'sample_rss_main.php'),
|
|
|
|
dir('html/user', 'rss_main.php'))
|
|
|
|
install(
|
|
|
|
srcdir('html/user', 'sample_status.php'),
|
|
|
|
dir('html/user', 'status.php'))
|
2003-10-03 05:53:28 +00:00
|
|
|
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
class Project:
|
|
|
|
def __init__(self,
|
2003-10-03 05:53:28 +00:00
|
|
|
short_name, long_name,
|
|
|
|
project_dir=None,key_dir=None,
|
|
|
|
master_url=None, cgi_url=None,
|
2003-10-17 09:04:13 +00:00
|
|
|
db_name=None,
|
|
|
|
production=False
|
|
|
|
):
|
2003-07-18 21:43:12 +00:00
|
|
|
init()
|
2003-10-03 05:53:28 +00:00
|
|
|
|
|
|
|
self.short_name = short_name
|
2003-07-18 21:43:12 +00:00
|
|
|
self.long_name = long_name or 'Project ' + self.short_name.replace('_',' ').capitalize()
|
2003-10-03 05:53:28 +00:00
|
|
|
|
|
|
|
self.project_dir = project_dir or os.path.join(options.projects_dir, self.short_name)
|
|
|
|
|
|
|
|
self.config = configxml.ConfigFile(self.dir('config.xml')).init_empty()
|
|
|
|
config = self.config.config
|
|
|
|
|
2005-01-17 00:21:19 +00:00
|
|
|
config.long_name = self.long_name
|
|
|
|
config.db_user = options.db_user
|
2004-01-16 00:12:27 +00:00
|
|
|
config.db_name = db_name or options.user_name + '_' + self.short_name
|
2005-01-17 00:21:19 +00:00
|
|
|
config.db_passwd = options.db_passwd
|
2005-02-17 20:35:41 +00:00
|
|
|
config.db_host = options.db_host
|
2003-10-03 05:53:28 +00:00
|
|
|
config.shmem_key = generate_shmem_key()
|
|
|
|
config.output_level = 3
|
2004-12-06 22:41:19 +00:00
|
|
|
config.uldl_dir_fanout = 1024
|
2004-11-24 07:17:46 +00:00
|
|
|
local_host = socket.gethostname()
|
|
|
|
config.host = local_host.split('.')[0]
|
2004-12-08 00:14:52 +00:00
|
|
|
config.min_sendwork_interval = 6
|
|
|
|
config.max_wus_to_send = 50
|
|
|
|
config.daily_result_quota = 500
|
|
|
|
config.disable_account_creation = 1
|
|
|
|
config.show_result = 1
|
2003-10-03 05:53:28 +00:00
|
|
|
|
|
|
|
config.master_url = master_url or os.path.join(options.html_url , self.short_name , '')
|
|
|
|
config.download_url = os.path.join(config.master_url, 'download')
|
|
|
|
config.cgi_url = cgi_url or os.path.join(options.cgi_url, self.short_name)
|
|
|
|
config.upload_url = os.path.join(config.cgi_url , 'file_upload_handler')
|
|
|
|
config.download_dir = os.path.join(self.project_dir , 'download')
|
|
|
|
config.upload_dir = os.path.join(self.project_dir , 'upload')
|
|
|
|
config.key_dir = key_dir or os.path.join(self.project_dir , 'keys')
|
2003-10-03 06:46:22 +00:00
|
|
|
config.app_dir = os.path.join(self.project_dir, 'apps')
|
2003-10-17 09:04:13 +00:00
|
|
|
if production:
|
|
|
|
config.one_result_per_user_per_wu = '1'
|
2003-10-03 06:46:22 +00:00
|
|
|
self.scheduler_url = os.path.join(config.cgi_url , 'cgi')
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
def dir(self, *dirs):
|
|
|
|
return apply(os.path.join,(self.project_dir,)+dirs)
|
|
|
|
|
|
|
|
def keydir(self, *dirs):
|
2003-10-03 05:53:28 +00:00
|
|
|
return apply(os.path.join,(self.config.config.key_dir,)+dirs)
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2005-02-15 20:50:28 +00:00
|
|
|
def logdir(self):
|
|
|
|
return os.path.join(self.project_dir, "log_"+self.config.config.host)
|
2004-01-15 23:53:13 +00:00
|
|
|
|
2003-07-18 21:43:12 +00:00
|
|
|
def create_keys(self):
|
2003-07-18 23:20:46 +00:00
|
|
|
if not os.path.exists(self.keydir()):
|
|
|
|
os.mkdir(self.keydir())
|
2003-07-18 21:43:12 +00:00
|
|
|
_gen_key(self.keydir('upload'))
|
|
|
|
_gen_key(self.keydir('code_sign'))
|
|
|
|
|
2004-01-15 23:53:13 +00:00
|
|
|
def create_logdir(self):
|
2005-02-15 20:50:28 +00:00
|
|
|
os.mkdir(self.logdir())
|
|
|
|
os.chmod(self.logdir(), 0777)
|
2004-01-15 23:53:13 +00:00
|
|
|
|
2003-07-18 21:43:12 +00:00
|
|
|
def query_create_keys(self):
|
2003-10-03 05:53:28 +00:00
|
|
|
return query_yesno("Keys don't exist in %s; generate them?"%self.keydir())
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
def keys_exist(self):
|
|
|
|
keys = ['upload_private', 'upload_public',
|
|
|
|
'code_sign_private', 'code_sign_public' ]
|
|
|
|
for key in keys:
|
|
|
|
if not os.path.exists(self.keydir(key)): return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
def install_project(self, scheduler_file = None):
|
|
|
|
if os.path.exists(self.dir()):
|
|
|
|
raise SystemExit('Project directory "%s" already exists; this would clobber it!'%self.dir())
|
|
|
|
|
|
|
|
verbose_echo(1, "Setting up server: creating directories");
|
2005-02-08 22:07:40 +00:00
|
|
|
|
2005-02-15 20:50:28 +00:00
|
|
|
create_project_dirs(self.project_dir);
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
if not self.keys_exist():
|
|
|
|
if self.query_create_keys():
|
|
|
|
verbose_echo(1, "Setting up server files: generating keys");
|
|
|
|
self.create_keys()
|
|
|
|
|
|
|
|
# copy the user and administrative PHP files to the project dir,
|
2003-10-03 05:53:28 +00:00
|
|
|
verbose_echo(1, "Setting up server files: copying files")
|
|
|
|
|
2005-02-15 20:50:28 +00:00
|
|
|
# Create the project log directory
|
|
|
|
self.create_logdir()
|
2004-01-15 23:53:13 +00:00
|
|
|
|
2003-10-03 05:53:28 +00:00
|
|
|
install_boinc_files(self.dir())
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2004-06-11 18:50:15 +00:00
|
|
|
# copy sample web files
|
|
|
|
install(srcdir('html/user/sample_index.php'),
|
|
|
|
self.dir('html/user/index.php'))
|
|
|
|
install(srcdir('html/project.sample/project.inc'),
|
|
|
|
self.dir('html/project/project.inc'))
|
|
|
|
install(srcdir('html/project.sample/project_specific_prefs.inc'),
|
|
|
|
self.dir('html/project/project_specific_prefs.inc'))
|
|
|
|
install(srcdir('html/project.sample/project_news.inc'),
|
|
|
|
self.dir('html/project/project_news.inc'))
|
2004-08-02 19:40:34 +00:00
|
|
|
install(srcdir('html/project.sample/cache_parameters.inc'),
|
|
|
|
self.dir('html/project/cache_parameters.inc'))
|
2004-06-11 18:50:15 +00:00
|
|
|
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2004-02-04 01:21:51 +00:00
|
|
|
my_symlink(self.config.config.download_dir, self.dir('html', 'user', 'download'))
|
|
|
|
my_symlink('../stats', self.dir('html/user/stats'))
|
|
|
|
my_symlink('../user_profile', self.dir('html/user/user_profile'))
|
2004-02-15 18:34:10 +00:00
|
|
|
my_symlink('../user_profile', self.dir('html/user_profile/user_profile'))
|
2003-10-03 05:53:28 +00:00
|
|
|
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
# Copy the sched server in the cgi directory with the cgi names given
|
2004-02-04 23:01:39 +00:00
|
|
|
# source_dir/html/user/schedulers.txt
|
2003-07-18 21:43:12 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
if scheduler_file:
|
|
|
|
r = re.compile('<scheduler>([^<]+)</scheduler>', re.IGNORECASE)
|
2004-02-04 01:21:51 +00:00
|
|
|
f = open(self.dir('html/user', scheduler_file))
|
2003-07-18 21:43:12 +00:00
|
|
|
for line in f:
|
|
|
|
# not sure if this is what the scheduler file is supposed to
|
|
|
|
# mean
|
|
|
|
match = r.search(line)
|
|
|
|
if match:
|
|
|
|
cgi_name = match.group(1)
|
|
|
|
verbose_echo(2, "Setting up server files: copying " + cgi_name);
|
|
|
|
install(builddir('sched/cgi'), self.dir('cgi-bin', cgi_name,''))
|
|
|
|
f.close()
|
|
|
|
else:
|
|
|
|
scheduler_file = 'schedulers.txt'
|
2004-02-04 01:21:51 +00:00
|
|
|
f = open(self.dir('html/user', scheduler_file), 'w')
|
2003-10-03 05:53:28 +00:00
|
|
|
print >>f, "<scheduler>" + self.scheduler_url.strip(), "</scheduler>"
|
2003-07-18 21:43:12 +00:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
verbose_echo(1, "Setting up database")
|
2005-02-17 20:35:41 +00:00
|
|
|
database.create_database(
|
|
|
|
config = self.config.config,
|
|
|
|
drop_first = options.drop_db_first
|
|
|
|
)
|
2003-09-22 23:55:39 +00:00
|
|
|
|
2003-10-03 05:53:28 +00:00
|
|
|
verbose_echo(1, "Setting up server files: writing config files")
|
|
|
|
|
|
|
|
self.config.write()
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
# create symbolic links to the CGI and HTML directories
|
|
|
|
verbose_echo(1, "Setting up server files: linking cgi programs")
|
2003-07-18 23:20:46 +00:00
|
|
|
if options.__dict__.get('cgi_dir'):
|
|
|
|
force_symlink(self.dir('cgi-bin'), os.path.join(options.cgi_dir, self.short_name))
|
|
|
|
if options.__dict__.get('html_dir'):
|
2004-02-04 01:21:51 +00:00
|
|
|
force_symlink(self.dir('html/user'), os.path.join(options.html_dir, self.short_name))
|
|
|
|
force_symlink(self.dir('html/ops'), os.path.join(options.html_dir, self.short_name+'_admin'))
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
def http_password(self, user, password):
|
2004-02-04 01:21:51 +00:00
|
|
|
'Adds http password protection to the html/ops directory'
|
|
|
|
passwd_file = self.dir('html/ops', '.htpassword')
|
|
|
|
f = open(self.dir('html/ops', '.htaccess'), 'w')
|
2003-07-18 21:43:12 +00:00
|
|
|
print >>f, "AuthName '%s Administration'" % self.long_name
|
|
|
|
print >>f, "AuthType Basic"
|
|
|
|
print >>f, "AuthUserFile %s" % passwd_file
|
|
|
|
print >>f, "require valid-user"
|
|
|
|
f.close()
|
|
|
|
shell_call("htpassword -bc %s %s %s" % (passwd_file, user, password))
|
|
|
|
|
|
|
|
def _run_sched_prog(self, prog, args='', logfile=None):
|
|
|
|
verbose_shell_call("cd %s && ./%s %s >> %s.log 2>&1" %
|
|
|
|
(self.dir('bin'), prog, args, (logfile or prog)))
|
|
|
|
|
|
|
|
def start_servers(self):
|
|
|
|
self.started = True
|
|
|
|
self._run_sched_prog('start', '-v --enable')
|
|
|
|
verbose_sleep("Starting servers for project '%s'" % self.short_name, 1)
|
|
|
|
|
|
|
|
def _build_sched_commandlines(self, progname, kwargs):
|
|
|
|
'''Given a KWARGS dictionary build a list of command lines string depending on the program.'''
|
|
|
|
each_app = False
|
|
|
|
if progname == 'feeder':
|
|
|
|
_check_vars(kwargs)
|
2003-08-15 23:04:36 +00:00
|
|
|
elif progname == 'transitioner':
|
|
|
|
_check_vars(kwargs)
|
2003-07-18 21:43:12 +00:00
|
|
|
elif progname == 'make_work':
|
|
|
|
work = kwargs.get('work', self.work)
|
2005-02-23 19:44:59 +00:00
|
|
|
_check_vars(kwargs, cushion=30, max_wus=0, wu_name=work.wu_template)
|
2004-07-19 23:05:44 +00:00
|
|
|
elif progname == 'sample_bitwise_validator':
|
2003-08-15 23:04:36 +00:00
|
|
|
_check_vars(kwargs)
|
2003-07-18 21:43:12 +00:00
|
|
|
each_app = True
|
|
|
|
elif progname == 'file_deleter':
|
|
|
|
_check_vars(kwargs)
|
2004-07-19 23:05:44 +00:00
|
|
|
elif progname == 'sample_dummy_assimilator':
|
2003-07-18 21:43:12 +00:00
|
|
|
_check_vars(kwargs)
|
|
|
|
each_app = True
|
|
|
|
else:
|
|
|
|
raise SystemExit("test script error: invalid progname '%s'"%progname)
|
2003-08-15 23:04:36 +00:00
|
|
|
cmdline = apply(build_command_line, [''], kwargs)
|
2003-07-18 21:43:12 +00:00
|
|
|
if each_app:
|
|
|
|
return map(lambda av: '-app %s %s'%(av.app.name,cmdline), self.app_versions)
|
|
|
|
else:
|
|
|
|
return [cmdline]
|
|
|
|
|
|
|
|
def sched_run(self, prog, **kwargs):
|
|
|
|
for cmdline in self._build_sched_commandlines(prog, kwargs):
|
|
|
|
self._run_sched_prog(prog, '-d 3 -one_pass '+cmdline)
|
|
|
|
def sched_install(self, prog, **kwargs):
|
|
|
|
for cmdline in self._build_sched_commandlines(prog, kwargs):
|
2003-10-03 05:53:28 +00:00
|
|
|
self.config.daemons.make_node_and_append("daemon").cmd = "%s -d 3 %s" %(prog, cmdline)
|
|
|
|
self.config.write()
|
|
|
|
# def sched_uninstall(self, prog):
|
|
|
|
# self.config_daemons = XXX filter(lambda l: l.find(prog)==-1, self.config_daemons)
|
|
|
|
# self.config.write()
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
def start_stripcharts(self):
|
|
|
|
map(lambda l: self.copy(os.path.join('stripchart', l), 'cgi-bin/'),
|
|
|
|
[ 'stripchart.cgi', 'stripchart', 'stripchart.cnf',
|
|
|
|
'looper', 'db_looper', 'datafiles', 'get_load', 'dir_size' ])
|
|
|
|
macro_substitute('BOINC_DB_NAME', self.db_name, srcdir('stripchart/samples/db_count'),
|
|
|
|
self.dir('bin/db_count'))
|
|
|
|
make_executable(self.dir('bin/db_count'))
|
|
|
|
|
|
|
|
self._run_sched_prog('looper' , 'get_load 1' , 'get_load')
|
|
|
|
self._run_sched_prog('db_looper' , '"result" 1' , 'count_results')
|
|
|
|
self._run_sched_prog('db_looper' , '"workunit where assimilate_state=2" 1' , 'assimilated_wus')
|
|
|
|
self._run_sched_prog('looper' , '"dir_size ../download" 1' , 'download_size')
|
|
|
|
self._run_sched_prog('looper' , '"dir_size ../upload" 1' , 'upload_size')
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
verbose_echo(1,"Stopping server(s) for project '%s'"%self.short_name)
|
|
|
|
self._run_sched_prog('start', '-v --disable')
|
|
|
|
self.started = False
|
|
|
|
|
|
|
|
def maybe_stop(self):
|
|
|
|
if self.started: self.stop()
|
|
|
|
|
2003-10-03 05:53:28 +00:00
|
|
|
def query_noyes(str):
|
|
|
|
verbose_echo(0,'')
|
|
|
|
return tools.query_noyes(str)
|
|
|
|
|
|
|
|
def query_yesno(str):
|
|
|
|
verbose_echo(0,'')
|
|
|
|
return tools.query_yesno(str)
|