Changeset 7662:3bbb48c223f3
- Timestamp:
- 11/27/07 23:35:57 (6 years ago)
- Branch:
- default
- Location:
- sage/dsage
- Files:
-
- 17 edited
-
all.py (modified) (2 diffs)
-
database/clientdb.py (modified) (2 diffs)
-
database/job.py (modified) (1 diff)
-
database/jobdb.py (modified) (5 diffs)
-
database/monitordb.py (modified) (6 diffs)
-
database/sql_functions.py (modified) (1 diff)
-
interface/dsage_interface.py (modified) (6 diffs)
-
misc/misc.py (modified) (1 diff)
-
scripts/dsage_server.py (modified) (3 diffs)
-
scripts/dsage_setup.py (modified) (4 diffs)
-
scripts/dsage_worker.py (modified) (3 diffs)
-
server/server.py (modified) (10 diffs)
-
server/stats.py (modified) (1 diff)
-
twisted/misc.py (modified) (1 diff)
-
twisted/pb.py (modified) (1 diff)
-
twisted/pubkeyauth.py (modified) (2 diffs)
-
web/web_server.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/dsage/all.py
r5209 r7662 21 21 22 22 import os 23 from sage.dsage.dsage import dsage24 23 from sage.dsage.dist_functions.all import * 25 24 from sage.dsage.misc.constants import DSAGE_DIR … … 31 30 log_level=0, 32 31 ssl=True): 33 """34 This object represents a connection to the distributed SAGE server.32 """ 33 This object represents a connection to the distributed SAGE server. 35 34 36 Parameters:37 server -- str (Default: 'localhost')38 port -- int (Default: 8081)39 username -- str40 pubkey_file -- str (Default: ~/.sage/dsage/dsage_key.pub)41 privkey_file -- str (Default: ~/.sage/dsage/dsage_key)42 log_level -- int (Default: 0)43 ssl -- int (Default: 1)35 Parameters: 36 server -- str (Default: 'localhost') 37 port -- int (Default: 8081) 38 username -- str 39 pubkey_file -- str (Default: ~/.sage/dsage/dsage_key.pub) 40 privkey_file -- str (Default: ~/.sage/dsage/dsage_key) 41 log_level -- int (Default: 0) 42 ssl -- int (Default: 1) 44 43 45 """44 """ 46 45 47 from sage.dsage.interface.dsage_interface import BlockingDSage 48 return BlockingDSage(server=server, port=port, 49 username=username, 50 pubkey_file=pubkey_file, 51 privkey_file=privkey_file, 52 ssl=ssl) 46 from sage.dsage.interface.dsage_interface import BlockingDSage 47 return BlockingDSage(server=server, port=port, username=username, 48 pubkey_file=pubkey_file, privkey_file=privkey_file, 49 log_leve=log_level, ssl=ssl) 53 50 -
sage/dsage/database/clientdb.py
r4644 r7662 59 59 60 60 self.tablename = self.TABLENAME 61 self.log_level = log_level 62 self.log_file=log_file 63 61 64 if test: 62 65 self.db_file = 'clientdb_test.db' … … 64 67 self.db_file = db_file 65 68 if not os.path.exists(self.db_file): 66 dir , file= os.path.split(self.db_file)67 if not os.path.isdir(dir ):68 os.mkdir(dir )69 dir_, file_ = os.path.split(self.db_file) 70 if not os.path.isdir(dir_): 71 os.mkdir(dir_) 69 72 self.con = sqlite3.connect(self.db_file, 70 73 isolation_level=None, -
sage/dsage/database/job.py
r6739 r7662 157 157 158 158 def get_data(self): 159 return self.jdict['data']159 return self.jdict['data'] 160 160 def set_data(self, value): 161 self.jdict['data'] = value161 self.jdict['data'] = value 162 162 data = property(fget=get_data, fset=set_data, fdel=None, 163 163 doc='Job data') -
sage/dsage/database/jobdb.py
r7307 r7662 25 25 26 26 from twisted.python import log 27 from twisted.enterprise import adbapi 28 29 from BTrees import OOBTree 30 import transaction 31 32 from sage.dsage.database.job import Job 27 33 28 import sage.dsage.database.sql_functions as sql_functions 34 29 from sage.dsage.misc.constants import DSAGE_DIR … … 57 52 self.db_file = db_file 58 53 if not os.path.exists(self.db_file): 59 dir , file= os.path.split(self.db_file)60 if dir == '':61 pass62 elif not os.path.isdir(dir ):63 os.mkdir(dir )54 dir_, file_ = os.path.split(self.db_file) 55 if dir_ == '': 56 pass 57 elif not os.path.isdir(dir_): 58 os.mkdir(dir_) 64 59 self.job_failure_threshold = job_failure_threshold 65 60 self.log_file = log_file … … 274 269 v = str(v) 275 270 try: 276 sql_functions.update_value(self.con, 'jobs', 'job_id', job_id, k, v) 271 sql_functions.update_value(self.con, 'jobs', 'job_id', 272 job_id, k, v) 277 273 except (sqlite3.InterfaceError, 278 274 sqlite3.OperationalError, … … 313 309 try: 314 310 jdict['data'] = str(jdict['data']) 315 except Exception, msg:311 except KeyError, msg: 316 312 pass 317 313 try: 318 314 jdict['result'] = str(jdict['result']) 319 except Exception, msg:315 except KeyError, msg: 320 316 pass 321 317 … … 381 377 """ 382 378 383 return sql_functions.update_value(self.con, 'jobs', 'job_id', job_id, 'killed', killed) 379 return sql_functions.update_value(self.con, 'jobs', 'job_id', 380 job_id, 'killed', killed) 384 381 385 382 def get_active_jobs(self): -
sage/dsage/database/monitordb.py
r7660 r7662 67 67 self.log_level = log_level 68 68 if not os.path.exists(self.db_file): 69 dir , file= os.path.split(self.db_file)70 if not os.path.isdir(dir ):71 os.mkdir(dir )69 dir_, file_ = os.path.split(self.db_file) 70 if not os.path.isdir(dir_): 71 os.mkdir(dir_) 72 72 self.con = sqlite3.connect(self.db_file, 73 73 isolation_level=None, … … 115 115 workers = host_info['workers'] 116 116 sage_version = host_info['sage_version'] 117 os = host_info['os']117 os_ = host_info['os'] 118 118 kernel_version = host_info['kernel_version'] 119 119 cpus = host_info['cpus'] … … 124 124 125 125 cur = self.con.cursor() 126 cur.execute(query, (uuid, hostname, ip, workers, sage_version, os ,126 cur.execute(query, (uuid, hostname, ip, workers, sage_version, os_, 127 127 kernel_version, cpus, cpu_speed, cpu_model, 128 128 mem_total, mem_free)) … … 142 142 workers = host_info['workers'] 143 143 sage_version = host_info['sage_version'] 144 os = host_info['os']144 os_ = host_info['os'] 145 145 kernel_version = host_info['kernel_version'] 146 146 cpus = host_info['cpus'] … … 151 151 152 152 cur = self.con.cursor() 153 cur.execute(query, (hostname, ip, workers, sage_version, os ,153 cur.execute(query, (hostname, ip, workers, sage_version, os_, 154 154 kernel_version, cpus, cpu_speed, cpu_model, 155 155 mem_total, mem_free, uuid)) … … 261 261 262 262 if connected and not busy: 263 query = """SELECT workers FROM monitors WHERE connected AND NOT busy""" 263 query = """ 264 SELECT workers FROM monitors WHERE connected AND NOT busy 265 """ 264 266 elif connected and busy: 265 query = """SELECT workers FROM monitors WHERE connected AND busy""" 267 query = """ 268 SELECT workers FROM monitors WHERE connected AND busy 269 """ 266 270 elif not connected and not busy: 267 query = """SELECT workers FROM monitors WHERE NOT connected AND NOT busy""" 271 query = """ 272 SELECT workers FROM monitors WHERE NOT connected AND NOT busy 273 """ 268 274 elif not connected and busy: 269 query = """SELECT workers FROM monitors WHERE NOT connected AND busy""" 275 query = """ 276 SELECT workers FROM monitors WHERE NOT connected AND busy 277 """ 278 270 279 cur = self.con.cursor() 271 280 cur.execute(query) -
sage/dsage/database/sql_functions.py
r7307 r7662 83 83 cur = con.cursor() 84 84 query = "DROP TABLE ?" 85 cur sor.execute(query, (table,))85 cur.execute(query, (table,)) 86 86 87 87 def add_trigger(con, trigger): -
sage/dsage/interface/dsage_interface.py
r7300 r7662 83 83 self.remoteobj = None 84 84 self.result = None 85 85 self.info_str = 'Connected to: %s:%s' 86 86 # public key authentication information 87 87 self.pubkey_str = keys.getPublicKeyString(filename=self.pubkey_file) … … 115 115 def __str__(self): 116 116 self.check_connected() 117 self.info_str = 'Connected to: %s:%s' % (self.server, self.port) 118 return self.info_str + '\r' 117 return self.info_str % (self.server, self.port) 119 118 120 119 def __call__(self, cmd, globals_=None, job_name=None): … … 179 178 factory = PBClientFactory() 180 179 181 if self. SSL== 1:180 if self.ssl == 1: 182 181 # Old, uses OpenSSL, SAGE uses GNUTLS now 183 182 # from twisted.internet import ssl … … 278 277 return JobWrapper(self.remoteobj, job) 279 278 280 def eval_dir(self, dir , job_name):279 def eval_dir(self, dir_, job_name): 281 280 from twisted.internet import defer 282 281 self.check_connected() 283 os.chdir(dir )282 os.chdir(dir_) 284 283 files = glob.glob('*.spyx') 285 284 deferreds = [] 286 for file in files:287 sage_cmd = open(file ).readlines()285 for file_ in files: 286 sage_cmd = open(file_).readlines() 288 287 d = self.remoteobj.callRemote('get_next_job_id') 289 d.addCallback(self._got_ id, sage_cmd, job_name, file=True,288 d.addCallback(self._got_job_id, sage_cmd, job_name, file=True, 290 289 type_='spyx') 291 290 d.addErrback(self._catch_failure) … … 744 743 from twisted.spread import pb 745 744 if self.remoteobj == None: 746 if self.LOG_LEVEL > 2:747 print 'self.remoteobj is None'745 # if self.LOG_LEVEL > 2: 746 # print 'self.remoteobj is None' 748 747 return 749 748 if self.status == 'completed': 750 if self.LOG_LEVEL > 2:751 print 'Stopping sync_job'749 # if self.LOG_LEVEL > 2: 750 # print 'Stopping sync_job' 752 751 if self.sync_job_task: 753 752 if self.sync_job_task.running: … … 831 830 832 831 if self.remoteobj == None: 833 raise NotConnectedException832 raise NotConnectedException 834 833 if self.status == 'completed': 835 834 return -
sage/dsage/misc/misc.py
r6801 r7662 32 32 33 33 """ 34 s = [chr(i) for i in [random.randint(65, 123) for n in range(length)]]35 34 36 return ''.join(s) 35 r_str = [chr(i) for i in [random.randint(65, 123) for n in range(length)]] 36 37 return ''.join(r_str) 37 38 38 def timedelta_to_seconds( d):39 def timedelta_to_seconds(time_delta): 39 40 """ 40 41 Converts a timedelta object into seconds. 41 42 42 43 """ 43 days, seconds, microseconds = (d.days, d.seconds, d.microseconds)44 44 45 seconds = float(days*24*60*60 + d.seconds + (d.microseconds/10.0**6)) 45 days, seconds, microseconds = (time_delta.days, 46 time_delta.seconds, 47 time_delta.microseconds) 48 49 seconds = float(days*24*60*60 + seconds + (microseconds/10.0**6)) 46 50 47 51 return seconds -
sage/dsage/scripts/dsage_server.py
r7660 r7662 55 55 56 56 # usage options 57 usage = ['usage: %prog [options]\n',57 usage_ = ['usage: %prog [options]\n', 58 58 'Bug reports to <yqiang@gmail.com>'] 59 59 60 parser = OptionParser(usage=''.join(usage ))60 parser = OptionParser(usage=''.join(usage_)) 61 61 62 62 parser.add_option('-p', '--port', … … 113 113 'started in blocking mode') 114 114 115 (options , args) = parser.parse_args()116 117 return options 115 (options_, args) = parser.parse_args() 116 117 return options_ 118 118 119 119 def create_manhole(): … … 210 210 COMP_DEFLATE, 211 211 COMP_NULL) 212 reactor.listenTLS(SERVER_PORT, client_factory, cred) 212 reactor.listenTLS(SERVER_PORT, client_factory, cred) 213 213 else: 214 214 reactor.listenTCP(SERVER_PORT, client_factory) -
sage/dsage/scripts/dsage_setup.py
r7657 r7662 98 98 print DELIMITER 99 99 print "Generating public/private key pair for authentication..." 100 print "Your key will be stored in %s/dsage_key" %DSAGE_DIR100 print "Your key will be stored in %s/dsage_key" % DSAGE_DIR 101 101 print "Just hit enter when prompted for a passphrase" 102 102 print DELIMITER … … 120 120 check_dsage_dir() 121 121 print "Choose a domain name for your SAGE notebook server," 122 print "for example, localhost (personal use) or %s (to allow outside connections)." %socket.getfqdn()122 print "for example, localhost (personal use) or %s (to allow outside connections)." % socket.getfqdn() 123 123 dn = raw_input("Domain name [localhost]: ").strip() 124 124 if dn == '': … … 126 126 dn = 'localhost' 127 127 128 template_dict = {'organization': 'SAGE (at %s)' %(dn),128 template_dict = {'organization': 'SAGE (at %s)' % (dn), 129 129 'unit': '389', 130 130 'locality': None, … … 157 157 w = '' 158 158 elif isinstance(val, list): 159 w = ' '.join(['"%s"' %x for x in val])159 w = ' '.join(['"%s"' % x for x in val]) 160 160 else: 161 w = '"%s"' %val162 s += '%s = %s \n' %(key, w)161 w = '"%s"' % val 162 s += '%s = %s \n' % (key, w) 163 163 164 164 template_file = os.path.join(DSAGE_DIR, 'cert.cfg') -
sage/dsage/scripts/dsage_worker.py
r7660 r7662 357 357 done, new = self.sage._get() 358 358 # If result.sobj exists, our calculation is done 359 result = open('result.sobj', 'rb').read() 359 result = open('result.sobj', 'rb').read() 360 360 done = True 361 361 except RuntimeError, msg: # Error in calling worker.sage._so_far() … … 370 370 done = False 371 371 if done: 372 try:373 cpu_time = cPickle.loads(open('cpu_time.sobj', 'rb').read())374 except IOError:375 cpu_time = -1 # This means that we could not get a cpu_time.376 self.free = True377 self.reset_checker()372 try: 373 cpu_time = cPickle.loads(open('cpu_time.sobj', 'rb').read()) 374 except IOError: 375 cpu_time = -1 # This means that we could not get a cpu_time. 376 self.free = True 377 self.reset_checker() 378 378 else: 379 379 result = cPickle.dumps('Job not done yet.', 2) … … 640 640 self.DATA = random_str(500) 641 641 # public key authentication information 642 self.pubkey_str = keys.getPublicKeyString(self.pubkey_file)642 self.pubkey_str = keys.getPublicKeyString(self.pubkey_file) 643 643 # try getting the private key object without a passphrase first 644 644 try: -
sage/dsage/server/server.py
r7660 r7662 20 20 import cPickle 21 21 import datetime 22 import xml.dom.minidom23 import cStringIO24 22 25 23 from twisted.spread import pb … … 52 50 self.monitordb = monitordb 53 51 self.clientdb = clientdb 54 self. LOG_LEVEL= log_level52 self.log_level = log_level 55 53 56 54 def register_client_factory(self, client_factory): … … 74 72 jdict = self.jobdb.get_job(anonymous=False) 75 73 if jdict == None: 76 if self. LOG_LEVEL> 3:74 if self.log_level > 3: 77 75 log.msg('[DSage, get_job]' + ' Job db is empty.') 78 76 return None 79 77 else: 80 78 job_id = jdict['job_id'] 81 if self. LOG_LEVEL> 3:79 if self.log_level > 3: 82 80 log.msg('[DSage, get_job]' + ' Sending job %s' % job_id) 83 81 jdict['status'] = 'processing' … … 149 147 jobs = self.jobdb.get_jobs_by_username(username, active) 150 148 151 if self. LOG_LEVEL> 3:149 if self.log_level > 3: 152 150 log.msg(jobs) 153 151 … … 163 161 """ 164 162 165 if self. LOG_LEVEL> 3:163 if self.log_level > 3: 166 164 log.msg('[DSage, submit_job] %s' % (jdict)) 167 165 if jdict['code'] is None: … … 217 215 """ 218 216 219 if self. LOG_LEVEL> 0:217 if self.log_level > 0: 220 218 log.msg('[DSage, get_next_job_id] Returning next job ID') 221 219 … … 235 233 """ 236 234 237 if self. LOG_LEVEL> 0:235 if self.log_level > 0: 238 236 log.msg('[DSage, job_done] %s called back' % (job_id)) 239 if self. LOG_LEVEL> 3:237 if self.log_level > 3: 240 238 log.msg('[DSage, job_done] output: %s ' % output) 241 239 log.msg('[DSage, job_done] completed: %s ' % completed) … … 278 276 job.status = 'new' # Put job back in the queue 279 277 280 if self. LOG_LEVEL> 1:278 if self.log_level > 1: 281 279 s = ['[DSage, job_failed] Job %s failed ' % (job_id), 282 280 '%s times. ' % (job.failures)] … … 297 295 298 296 """ 299 297 300 298 if job_id == None: 301 if self. LOG_LEVEL> 0:299 if self.log_level > 0: 302 300 log.msg('[DSage, kill_job] Invalid job id') 303 301 return None … … 305 303 try: 306 304 self.jobdb.set_killed(job_id, killed=True) 307 if self. LOG_LEVEL> 0:305 if self.log_level > 0: 308 306 log.msg('Killed job %s' % (job_id)) 309 307 except Exception, msg: -
sage/dsage/server/stats.py
r7660 r7662 19 19 from xml.etree.ElementTree import (ElementTree as ET, 20 20 Element, 21 SubElement, 22 dump, 23 XML) 21 SubElement) 24 22 from cStringIO import StringIO 25 23 -
sage/dsage/twisted/misc.py
r3837 r7662 17 17 ############################################################################## 18 18 19 import threading , sys19 import threading 20 20 21 21 # This code is from -
sage/dsage/twisted/pb.py
r7641 r7662 402 402 log.msg('(%s, %s) connected' % (avatarID, kind)) 403 403 404 return pb.IPerspective, avatar, lambda a =avatar:a.detached(avatar,405 mind)404 return pb.IPerspective, avatar, lambda a = avatar:a.detached(avatar, 405 mind) -
sage/dsage/twisted/pubkeyauth.py
r4933 r7662 37 37 raise TypeError('Invalid key type.') 38 38 except IOError, msg: 39 key = pubkey_file39 key = filename 40 40 41 41 return key … … 56 56 def requestAvatarId(self, credentials): 57 57 if IAnonymous.providedBy(credentials): 58 return 'Anonymous'58 return 'Anonymous' 59 59 60 60 # read the authentication table to make sure we have a fresh copy -
sage/dsage/web/web_server.py
r7660 r7662 66 66 except AttributeError: # This is a fix for older databases. 67 67 update_time = "N/A" 68 html +="""68 html += """ 69 69 <tr class='tr%s' 70 70 """ % (i % 2) 71 html +="""71 html += """ 72 72 <td><a href='#%s' onClick="getJobDetails('%s')">%s</a></td> 73 73 <td>%s</td> … … 153 153 154 154 """ 155 156 157 from xml.etree.ElementTree import (ElementTree as ET, 158 Element, 159 SubElement, 160 dump, 161 XML) 155 162 156 root = Element('jobs') 163 157 … … 213 207 <td>%s</td> 214 208 </tr> 215 """ % (k, v)209 """ % (k, v) 216 210 217 211 html += """
Note: See TracChangeset
for help on using the changeset viewer.
