Unverified Commit 27758a9c authored by Kevin Reed's avatar Kevin Reed Committed by GitHub
Browse files

Merge pull request #2477 from BOINC/dpa_python3

Start migration to python 3
parents e52630ad 7c74e672
......@@ -4,7 +4,7 @@
# add_util.py - code shared between add and xadd
import database, tools
from Boinc import database, tools
import time, pprint
import MySQLdb
......@@ -128,9 +128,9 @@ def translate_database_arg(database_table, arg, value):
if len(results) == 0:
raise SystemExit('No %s "%s" found' %(arg,value))
if len(results) > 1:
print >>sys.stderr, 'Too many %ss match "%s": '%(arg,value)
print('Too many %ss match "%s": '%(arg,value), sys.stderr)
for result in results:
print >>sys.stderr, ' ', result.name
print (' '+result.name, sys.stderr)
raise SystemExit
return results[0]
......@@ -158,14 +158,14 @@ def do_add_object(add_object, untranslated_args_dict, skip_old=False):
args_dict = translate_args_dict(add_object, untranslated_args_dict)
check_required_arguments(add_object, args_dict)
dbobject = add_object.DatabaseObject(**args_dict)
print "Processing", dbobject, "..."
print("Processing"+dbobject+"...")
# print "Commiting", dbobject, "with args:"
# pprint.pprint(dbobject.__dict__)
try:
dbobject.commit()
except MySQLdb.MySQLError, e:
except MySQLdb.MySQLError as e:
if skip_old and exception_is_duplicate_entry(e):
print " Skipped existing", dbobject
print(" Skipped existing"+dbobject)
return
else:
raise SystemExit('Error committing %s: %s' %(dbobject, e))
......@@ -175,5 +175,5 @@ def do_add_object(add_object, untranslated_args_dict, skip_old=False):
id = dbobject.id
del dbobject
dbobject = add_object.DatabaseObject._table[id]
print " Committed", dbobject, "; values:"
print(" Committed"+dbobject+"; values:")
pprint.pprint(dbobject.__dict__)
......@@ -89,14 +89,15 @@ class ConfigDict:
set_element( get_element(self._node,key,1), str(self.__dict__[key]) )
def debug_print(self):
for key in self.__dict__.keys():
print key.rjust(15), '=', self.__dict__[key]
print(key.rjust(15), '=', self.__dict__[key])
class ConfigDictList(list):
def __init__(self, dom_node, item_class=ConfigDict):
self._node = dom_node
list.__init__(self, map(item_class, get_child_elements(self._node)))
def save(self):
map(ConfigDict.save, self)
for item in self:
ConfigDict.save(item)
def make_node_and_append(self, name):
'''Make a new ConfigDict and append it. Returns new ConfigDict.'''
new_element = append_new_element(self._node, name)
......@@ -129,7 +130,7 @@ class XMLConfig:
except:
if not failopen_ok:
raise Exception("Couldn't parse XML config\n")
print >>sys.stderr, "Warning: couldn't parse XML file"
print("Warning: couldn't parse XML file", sys.stderr)
self._init_empty_xml()
try:
self._get_elements()
......@@ -145,7 +146,7 @@ class XMLConfig:
if not output:
output = open(self.filename,'w')
self.xml.writexml(output, "", " "*4, "\n")
print >>output
output.write('')
return self
def _set_elements(self):
pass
......@@ -22,8 +22,8 @@ USAGE: from Boinc import configxml
'''
import sys
import boinc_project_path
from boincxml import *
from Boinc import boinc_project_path
from Boinc.boincxml import *
default_config_file = None
......@@ -55,22 +55,22 @@ class ConfigFile(XMLConfig):
def debug_print_all(self):
'''print everything to stdout.'''
print 'Debug dump of', self.filename
print '-- parsed xml -------------------------------------------------------'
print('Debug dump of', self.filename)
print('-- parsed xml -------------------------------------------------------')
self.xml.writexml(sys.stdout)
print
print '-- Config -----------------------------------------------------------'
print()
print('-- Config -----------------------------------------------------------')
self.config.debug_print()
print
print '-- Daemons ------------------------------------------------------------'
print()
print('-- Daemons ------------------------------------------------------------')
for daemon in self.daemons:
daemon.debug_print()
print
print
print '-- Tasks ------------------------------------------------------------'
print()
print()
print('-- Tasks ------------------------------------------------------------')
for task in self.tasks:
task.debug_print()
print
print()
default_xml = '<boinc><config></config></boinc>'
# keeps BoincCron's timestamp status file
......@@ -102,8 +102,8 @@ def default_config():
if __name__ == '__main__':
config = ConfigFile().read()
# print "setting config.enabled = True"
# print("setting config.enabled = True")
# config.enabled = True
config.debug_print_all()
print " -- saving xml and rewriting -----------------------------------------------"
print(" -- saving xml and rewriting -----------------------------------------------")
config.write(sys.stdout)
......@@ -28,9 +28,9 @@ for user in database.Users.find():
'''
import configxml
from util import *
from db_base import *
from Boinc import configxml
from Boinc.util import *
from Boinc.db_base import *
ID = '$Id$'
......
......@@ -42,17 +42,17 @@ class DatabaseInconsistency(Exception):
self.search_table,
self.search_kwargs,
'\n'.join(
map(lambda o:" %s#%s %s"%(o._table.table,o.__dict__.get('id'),o), self.search_tree))
))
[ " %s#%s %s"%(o._table.table,o.__dict__.get('id'),o) for o in self.search_tree ]
)))
class Debug:
def __init__(self):
self.html = False
def printline(self,s):
if self.html:
print "<!-- ## %s -->"%s
print("<!-- ## %s -->"%s)
else:
print >>sys.stderr, "##", s
print("##"+s, sys.stderr)
debug = Debug()
debug.mysql = not not os.environ.get('DEBUG_DB')
......@@ -61,7 +61,7 @@ def _execute_sql(cursor, command):
'''Same as ``cursor.execute(command)``, but more verbose on error.'''
try:
cursor.execute(command)
except MySQLdb.MySQLError, e:
except MySQLdb.MySQLError as e:
e.args += (command,)
raise e
......@@ -323,7 +323,7 @@ class DatabaseTable:
return
def _create_objects_from_sql_results(self, results, kwargs):
return map(self._create_object_from_sql_result, results)
return [ self._create_object_from_sql_result for result in results ]
def _create_object_from_sql_result(self, result):
id = result['id']
......@@ -445,7 +445,7 @@ class DatabaseObject:
def do_init(self, kwargs):
try:
self.database_fields_to_self(kwargs)
except DatabaseInconsistency, e:
except DatabaseInconsistency as e:
e.search_tree.append(self)
raise
# if no id then object starts dirty
......@@ -521,7 +521,7 @@ def init_table_classes(database_classes_, more_id_lookups = {}):
DatabaseObject.id_lookups.update(more_id_lookups)
database_tables = map(lambda c: c._table, database_classes)
database_tables = [ c._table for c in database_classes ]
def check_database_consistency():
'''Raises DatabaseInconsistency on error.
......@@ -530,21 +530,21 @@ def check_database_consistency():
'''
options.LAZY_LOOKUPS = False
for table in database_tables:
print '\rChecking %s: [counting]' %(table.table),
print('\rChecking %s: [counting]' %(table.table))
sys.stdout.flush()
count = table.count()
i = 0
j_limit = int(count / 100) # show progress every 1%
j = j_limit
print '\rChecking %s: [iterating]' %(table.table),
print('\rChecking %s: [iterating]' %(table.table))
sys.stdout.flush()
for object in table.iterate():
# we don't need to do anything here; just iterating through the
# database will automatically read everything into memory
i += 1
if j == j_limit:
print '\rChecking %s: [%d/%d] %3.f%%' %(table.table, i, count, 100.0*i/count),
print('\rChecking %s: [%d/%d] %3.f%%' %(table.table, i, count, 100.0*i/count))
sys.stdout.flush()
j = 0
j += 1
print '\rChecking %s: all %d rows are good' %(table.table, count)
print('\rChecking %s: all %d rows are good' %(table.table, count))
......@@ -7,7 +7,7 @@
##
## will look prettier if you import this module.
import database
from Boinc import database
def MixIn(pyClass, mixInClass):
pyClass.__bases__ = (mixInClass,) + pyClass.__bases__
......
......@@ -10,9 +10,9 @@ USAGE: from Boinc import projectxml
'''
import sys
import boinc_project_path
from boincxml import *
from add_util import *
from Boinc import boinc_project_path
from Boinc.boincxml import *
from Boinc.add_util import *
default_project_file = None
......@@ -27,7 +27,7 @@ class ProjectFile(XMLConfig):
default_project_file = self
def _get_elements(self):
self.xml_boinc = get_element(self.xml, 'boinc', optional=False)
self.elements = ConfigDictList(self.xml_boinc)
self.elements = ConfigDictList(self.xml_boinc)
self.add_objects_and_args = []
for node in self.xml_boinc.childNodes:
add_object = add_objects.get(node.nodeName)
......@@ -35,13 +35,13 @@ class ProjectFile(XMLConfig):
raise SystemExit("Error in %s: No such object '%s' to add." %(self.filename,node.nodeName))
self.add_objects_and_args.append((add_object, get_elements_as_dict(node)))
def _set_elements(self):
self.elements.save()
self.elements.save()
def commit_all(self):
'''Commits all new data to the BOINC project database.'''
for add_object, untranslated_args_dict in self.add_objects_and_args:
try:
do_add_object(add_object, untranslated_args_dict, skip_old=True)
except AddObjectException, e:
except AddObjectException as e:
raise SystemExit('Error in %s: %s' %(self.filename,e))
default_xml = '<boinc></boinc>'
......
This diff is collapsed.
## $Id$
import configxml
from Boinc import configxml
try:
# use new hashlib if available
from hashlib import md5
......@@ -62,15 +62,21 @@ def file_size(path):
f.seek(0,2)
return f.tell()
def query_yesno(str):
def query_yesno(question):
'''Query user; default Yes'''
print str, "[Y/n] ",
return not raw_input().strip().lower().startswith('n')
valid = ('yes', 'y', '')
choice = input(question + "[Y/n] ").lower()
if choice in valid:
return True
return False
def query_noyes(str):
def query_noyes(question):
'''Query user; default No'''
print str, "[y/N] ",
return raw_input().strip().lower().startswith('y')
valid = ('yes', 'y')
choice = input(question + "[y/N] ").lower()
if choice in valid:
return True
return False
def get_output_file_path(filename):
""" Return the filename's path in the upload directory
......
#!/usr/bin/env python
#!/usr/bin/env python3
# $Id$
# Creates a new BOINC project.
......@@ -67,7 +67,7 @@ def syntax_error(str):
raise SystemExit('%s; See "%s --help" for help\n' % (str,sys.argv[0]))
def usage():
print HELP
print(HELP)
raise SystemExit
try:
......@@ -96,7 +96,7 @@ try:
'web_only',
]
)
except getopt.GetoptError, e:
except getopt.GetoptError as e:
syntax_error(e)
options.url_base = None
......@@ -184,7 +184,7 @@ defopt('db_user' , 'USER_NAME', isdir=False)
defopt('db_passwd' , '', isdir=False)
defopt('db_host' , '', isdir=False)
print "Creating project '%s' (short name '%s'):" %(project_longname, project_shortname)
print("Creating project '%s' (short name '%s'):" %(project_longname, project_shortname))
for k in [
'project_root',
'project_host',
......@@ -195,7 +195,7 @@ for k in [
'db_name',
'db_host',
]:
print k.upper().rjust(15), "=", options.__dict__[k]
print(k.upper().rjust(15), "=", options.__dict__[k])
project_root_parent = os.path.realpath(os.path.join(options.project_root,'..'))
if not os.path.exists(project_root_parent):
......@@ -206,7 +206,7 @@ if os.path.exists(options.project_root):
if not options.no_query:
if not query_noyes('Delete %s?'%options.project_root):
raise SystemExit('Aborted')
print "Deleting", options.project_root
print("Deleting", options.project_root)
rmtree(options.project_root)
else:
raise SystemExit('Project root already exists! Specify --delete_prev_inst --drop_db_first to clobber')
......@@ -239,7 +239,7 @@ project.sched_install('feeder')
project.sched_install('transitioner')
project.sched_install('file_deleter')
if options.test_app:
project.config.daemons.make_node_and_append("daemon").cmd = 'sample_work_generator -d 3'
project.config.daemons.make_node_and_append("daemon").cmd = 'sample_work_generator -d 3 --app example_app'
project.config.daemons.make_node_and_append("daemon").cmd = 'sample_bitwise_validator -d 3 --app example_app'
project.config.daemons.make_node_and_append("daemon").cmd = 'sample_assimilator -d 3 --app example_app'
......@@ -317,14 +317,14 @@ if not options.no_db:
try:
os.system('cd '+proot+'/html/ops; ./db_schemaversion.php > '+proot+'/db_revision')
except:
print '''Couldn't set db schema version number'''
print('''Couldn't set db schema version number''')
try:
os.system('cd '+proot+'/html/ops; ./update_translations.php -d 1')
except:
print '''Couldn't install translation files'''
print('''Couldn't install translation files''')
print '''Done installing default daemons.'''
print ('''Done installing default daemons.''')
# copy the test app if needed
if options.test_app:
......@@ -348,8 +348,7 @@ httpd_conf_template_filename = os.path.join(
project_shortname+'.httpd.conf'
)
print >>open(httpd_conf_template_filename,'w'), '''
content ='''
## Settings for BOINC project %(project_longname)s
Alias /%(project_shortname)s/download %(proot)s/download
......@@ -404,24 +403,32 @@ print >>open(httpd_conf_template_filename,'w'), '''
Require all granted
</Directory>
''' %locals()
''' % locals()
f = open(httpd_conf_template_filename,'w')
f.write(content)
f.close()
htaccess_filename = options.project_root+'/html/ops/.htaccess'
htpasswd_filename = options.project_root+'/html/ops/.htpasswd'
print >>open(htaccess_filename, 'w'), '''
content = '''
AuthName "%(project_shortname)s"
AuthType Basic
AuthUserFile %(htpasswd_filename)s
require valid-user
'''%locals()
f = open(htaccess_filename, 'w')
f.write(content)
f.close()
cronjob_filename = os.path.join(
options.project_root,
project_shortname+'.cronjob'
)
print >>open(cronjob_filename,'w'), '''0,5,10,15,20,25,30,35,40,45,50,55 * * * * cd %(proot)s ; %(proot)s/bin/start --cron
'''%locals()
f = open(cronjob_filename,'w')
f.write('0,5,10,15,20,25,30,35,40,45,50,55 * * * * cd %(proot)s ; %(proot)s/bin/start --cron\n' %locals())
f.close()
readme_filename = os.path.join(
options.project_root,
......@@ -459,7 +466,7 @@ See the online documentation at http://boinc.berkeley.edu/
html_user_url = options.html_user_url
html_ops_url = options.html_ops_url
print >>open(readme_filename,'w'), '''Steps to complete installation:
content = '''Steps to complete installation:
- Change Apache configuration (as root):
......@@ -506,9 +513,12 @@ Home page (and master URL): %(html_user_url)s
Administrative page: %(html_ops_url)s
%(compute_msg)s
'''%locals()
f = open(readme_filename,'w')
f.write(content)
f.close()
print '''
print('''
Done creating project. Please view
%(readme_filename)s
for important additional instructions.
'''%locals()
'''%locals())
#!/usr/bin/env python
#!/usr/bin/env python3
# $Id$
......@@ -24,7 +24,7 @@ from Boinc.setup_project import *
import os, getopt
def usage():
print "Usage: upgrade [--web_only | --server_only] [--srcdir DIR] project_root"
print ("Usage: upgrade [--web_only | --server_only] [--srcdir DIR] project_root")
raise SystemExit
def syntax_error(str):
......@@ -32,7 +32,7 @@ def syntax_error(str):
try:
opts, args = getopt.getopt(sys.argv[1:], '', ['help', 'web_only', 'server_only', 'srcdir='])
except getopt.GetoptError, e:
except getopt.GetoptError as e:
syntax_error(e)
home = os.path.expanduser('~')
......@@ -65,7 +65,7 @@ if not options.srcdir:
syntax_error('Not running in the source directory and --srcdir was not specified')
if not options.web_only:
print "Don't forget to do 'make' first!"
print ("Don't forget to do 'make' first!")
if not tools.query_noyes("Overwrite files in "+INSTALL_DIR):
raise SystemExit
......@@ -74,19 +74,19 @@ if not options.web_only:
if os.system('cd '+INSTALL_DIR+'; ./bin/stop'):
raise SystemExit("Couldn't stop project!")
print "Upgrading files... "
print ("Upgrading files... ")
options.install_method = 'copy'
init()
install_boinc_files(INSTALL_DIR, not options.server_only, not options.web_only)
print "Upgrading files... done"
print ("Upgrading files... done")
print "Updating translations"
print ("Updating translations")
try:
os.system('cd '+INSTALL_DIR+'/html/ops; ./update_translations.php -d 1')
except:
print '''Couldn't install translation files'''
print ('''Couldn't install translation files''')
opt = '';
if options.server_only:
......@@ -94,15 +94,15 @@ if options.server_only:
if options.web_only:
opt = ' --web'
print "Checking for DB updates"
print ("Checking for DB updates")
os.system('cd '+INSTALL_DIR+'/html/ops; ./upgrade_db.php'+opt)
if os.path.exists(INSTALL_DIR+'/html/project/project_news.inc'):
print '''\
print ('''\
html/project/project_news.inc is deprecated.
Run html/ops/news_convert.php to convert project news to forum format.
'''
''')
if not options.web_only:
print "Run `bin/start' to restart the project."
print ("Run `bin/start' to restart the project.")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment