def install_pgplot(): # Here will install the pgplot os.system('cp drivers.list '+global_setting.AstroSoft_pgplot) # os.system('cp makefile_pgplot ' + global_setting.AstroSoft_pgplot+'/makefile_pgplot') os.chdir(global_setting.AstroSoft_Src) os.system('tar zxvf '+ pgplot52_name) os.chdir(global_setting.AstroSoft_pgplot) #os.system('wget http://blog.csdn.net/shaoguangleo/article/details/drivers.list'); os.system(global_setting.AstroSoft_Src+'/pgplot/makemake '+global_setting.AstroSoft_Src + '/pgplot linux g77_gcc_aout') substitute.substitute('makefile','makefile_pgplot','FCOMPL=g77','FCOMPL=gfortran\n') os.system('cp makefile_pgplot makefile') os.system('make') os.system('make cpg') os.system('make clean') print 'DONE' #install_package.install_package(global_setting.AstroSoft_psrchive,psrchive_name,configure_option,4) pass
def install_pgplot(): # Here will install the pgplot os.system('cp drivers.list ' + global_setting.AstroSoft_pgplot) # os.system('cp makefile_pgplot ' + global_setting.AstroSoft_pgplot+'/makefile_pgplot') os.chdir(global_setting.AstroSoft_Src) os.system('tar zxvf ' + pgplot52_name) os.chdir(global_setting.AstroSoft_pgplot) #os.system('wget http://blog.csdn.net/shaoguangleo/article/details/drivers.list'); os.system(global_setting.AstroSoft_Src + '/pgplot/makemake ' + global_setting.AstroSoft_Src + '/pgplot linux g77_gcc_aout') substitute.substitute('makefile', 'makefile_pgplot', 'FCOMPL=g77', 'FCOMPL=gfortran\n') os.system('cp makefile_pgplot makefile') os.system('make') os.system('make cpg') os.system('make clean') print 'DONE' #install_package.install_package(global_setting.AstroSoft_psrchive,psrchive_name,configure_option,4) pass
def renderbrowseresults(self, sql, includemissing=False): """Paint a table of the results of a SQL statement.""" global blogic f = open('browse_result.html') results_template = f.read() f.close() f = open('missing_result.html') missing_template = f.read() f.close() results = [] bgcolor = '' for row in db.GetRows(sql): this_track = track.Track(db) this_track.FromId(row['id']) rendered = this_track.RenderValues() (rendered['mp3_url'], rendered['mp3_urlfile']) = blogic.findMP3( row['id'], client_id=self.client_id) if not 'creation_time' in rendered: rendered['creation_time'] = '' if rendered['mp3_url']: if bgcolor == 'bgcolor="#DDDDDD"': bgcolor = '' else: bgcolor = 'bgcolor="#DDDDDD"' rendered['bgcolor'] = bgcolor results.append( substitute.substitute(results_template, rendered)) else: if includemissing: results.append( substitute.substitute(missing_template, rendered)) self.log('Skipping row with no MP3 URL: %s' % repr(rendered)) return results
def handleurl_flash(self, urlpath, post_data): """Pretty graphs done with flash wrapped in HTML.""" global sensor_names db = MySQLdb.connect(user=FLAGS.dbuser, db=FLAGS.dbname) cursor = db.cursor(MySQLdb.cursors.DictCursor) args = urlpath.split('/') (ranges, times, step_size) = self.ParseTimeField(args[2]) links = [ self.time_link(urlpath, args[2], ranges[0], -one_day, '<<'), self.time_link(urlpath, args[2], ranges[0], one_day, '>>'), '<a href="/chart/%s">Static</a>' % '/'.join(args[2:]), '<a href="/table/%s">Table</a>' % '/'.join(args[2:]), '<a href="/csv/%s">CSV</a>' % '/'.join(args[2:]), '<a href="/json/%s">JSON</a>' % '/'.join(args[2:]) ] self.log('Time ranges: %s' % repr(ranges)) data = [] head = [] if len(args) < 4: data = self.AvailableSensors(cursor, ranges[0]) else: sensors = mhttp.urldecode(args[3]).split(',') data = [ '<h1>%s</h1><ul>' % ', '.join(sensors), '<div id="my_chart"></div>', '</ul>' ] f = open('ofc-helper.html') template = f.read() f.close() head = substitute.substitute( template, subst={'data_file': urlpath.replace('flash', 'json')}) self.sendfile('index.html', subst={ 'head': head, 'data': '\n'.join(data), 'links': ' '.join(links), 'refresh': '3600' })
f = open(path) f.read(inset) data += f.read() f.close() except Exception, e: self.senderror(404, 'File read error: %s (%s)' % (path, e)) return extn = path.split('.')[-1] mime_type = _CONTENT_TYPES.get(extn, 'application/octet-stream') if mime_type.find('text/') != -1: if not subst: subst = {} data = substitute.substitute(data, subst) self.sendheaders( 'HTTP/1.1 200 OK\r\n' 'Content-Type: %s\r\n' 'Content-Length: %s\r\n' '%s\r\n' % (mime_type, len(data), '\r\n'.join(self.extra_headers))) if mime_type == 'text/xml': for l in data.split('\n'): self.log('REPLY %s' % l, console=FLAGS.showresponse) self.buffer += data def senddata(self, data): """Send just some data."""
def handleurl_cdscontrol(self, urlfile, post_data): """uPnP CDS endpoint control.""" global blogic object_id = None object_id_re = re.compile('<ObjectID>(.*)</ObjectID>') for l in post_data.split('\r\n'): m = object_id_re.match(l) if m: object_id = m.group(1) if object_id: self.log('uPnP request for object id %s' % object_id) if object_id == '0': f = open('upnp_results.xml') results_template = f.read() f.close() results = [] for title in ['All', 'Recent']: result = substitute.substitute(results_template, {'title': title}) self.log('XML %s' % result, console=FLAGS.showresponse) results.append(self.xmlsafe(result)) self.sendfile('upnp_browseresponse.xml', subst={ 'result': '\n'.join(results), 'num_returned': len(results), 'num_matches': len(results) }) elif object_id == 'All' or object_id == 'Recent': skips.setdefault(self.addr[0], 0) rendered = blogic.picktrack(recent=(object_id == 'Recent'), client_id=self.client_id, skips=skips[self.addr[0]]) self.log('uPnP track selection %s' % rendered['id']) rendered['ip'] = FLAGS.ip rendered['port'] = FLAGS.port rendered['objectid'] = object_id f = open('upnp_song.xml') results = f.read() f.close() results = substitute.substitute(results, rendered) for l in results.split('\n'): self.log('XML %s' % l, console=FLAGS.showresponse) results = self.xmlsafe(results) self.sendfile('upnp_browseresponse.xml', subst={ 'result': results, 'num_returned': 1, 'num_matches': 1000 }) else: self.senderror(501, 'Unknown object ID')
__author__ = 'n3tn0' __version__ = '0.0.1' from getpass import getpass import letnum from duplicate_remove import rmv_dupe from substitute import substitute def create_decrypt_key(password): """ Creates the letter substitution key from a given password. :param password: Password to create the key from :return: Dictionary containing sets of letters """ password = letnum.l2n(password) alphakey = {} x = 1 for num in range(1, 26): password.append(num) numkey = rmv_dupe(password) for a in numkey: alphakey.update({letnum.nl[x]: letnum.nl[a]}) x += 1 key = dict(alphakey.items() + letnum.sym.items()) return key ciphertext = raw_input('Encrypted text: ') passkey = getpass('Passkey: ') cleartext = substitute(ciphertext, passkey) print cleartext
from duplicate_remove import rmv_dupe from substitute import substitute def create_encrypt_key(password): """ Creates a letter substitution dictionary object based on the Viper Encryption Cypher :param password: Password to create the key from :return: Dictionary containing sets of letters """ password = letnum.l2n(password) alphakey = {} x = 1 for num in range(1, 26): password.append(num) numkey = rmv_dupe(password) for a in numkey: alphakey.update({letnum.nl[a]: letnum.nl[x]}) x += 1 key = dict(alphakey.items() + letnum.sym.items()) return key cleartext = raw_input('Enter text: ') passkey = getpass('Passkey: ') key = create_encrypt_key(passkey) encrypted = substitute(cleartext, key) print encrypted
i += 1 sys.stderr.write('%s: %d accounts, %d debt, %d per account, ' '%d corrected per account\n' %(dt.strftime('%m/%Y'), accounts, balance, balance_per_account, balance_per_account * correction)) if balance_per_account > max_balance: max_balance = balance_per_account except Exception, e: sys.stderr.write('Exception %s: %s, %s\n' %(e, row[0], row[10])) # Write output graph per_elem = substitute.substitute(json_element_template, subst={'color': 'FF0000', 'name': 'Balance per account', 'values': ', '.join(peraccount_values), 'x_step': 36}) inf_elem = substitute.substitute(json_element_template, subst={'color': '00FF00', 'name': ('Balance per account ' '(corrected for inflation)'), 'values': ', '.join(inflation_corrected_values), 'x_step': 36}) out = substitute.substitute(json_template, subst={'title': 'Australian credit card debt', 'elements': '%s,\n%s' %(per_elem, inf_elem), 'x_min': x_labels[0], 'x_max': x_labels[-1],
def handleurl_json(self, urlpath, post_data): """A table of JSON formatted data.""" # If terse is set, we drop repeated values and assume the renderer # can handle that with a horizontal line. This is true for the flash # graphing engine for example global sensor_names args = urlpath.split('/') (ranges, times, step_size) = self.ParseTimeField(args[2]) data = [] incomplete = True terse = False for param in args[1].split(','): self.log('Considering table param: %s' % param) if param == 'noincomplete': incomplete = False if param == 'terse': terse = True self.log('Table parameters: incomplete = %s, terse = %s' % (incomplete, terse)) if len(args) < 4: data = self.AvailableSensors(cursor, ranges[0]) self.senddata('\n'.join(data)) else: (start_epoch, end_epoch, step_size, returned, values) = self.FetchTableData(args) if len(ranges) == 1: xformat = '#date:j/n g:i#' else: xformat = '#date: g:i#' f = open('data.json.element') template = f.read() f.close() colors = [ '0000FF', '00FF00', 'FF0000', '88ddff', 'bb0011', '11aaff', '9DAF72', '566047', '562F32', '462D44', '859731', '640E27', 'AD0066', 'D13D94', 'F5851F', 'CADA2A', '81A4B9', 'CFE8F6' ] y_min = 0 y_max = 0 elements = [] self.log('Iterating returned values: %s' % returned) for r in returned: upto = ranges[0][0] float_values = [] previous = None for v in values[r]: try: current = float(v) if not terse: float_values.append('{"x": %d, "y": %.03f}' % (upto, current)) else: if current != previous: if previous is not None: float_values.append( '{"x": %d, "y": %.03f}' % (upto, previous)) float_values.append('{"x": %d, "y": %.03f}' % (upto, current)) previous = current if current > y_max: y_max = current if current < y_min: y_min = current except: pass upto += step_size elements.append( substitute.substitute(template, subst={ 'name': sensor_names.get(r, r), 'values': ', '.join(float_values), 'color': colors[returned.index(r)] })) elements.reverse() self.sendfile('data.json', subst={ 'y_min': y_min, 'y_max': y_max, 'y_step': (y_max - y_min) / 15, 'elements': ', '.join(elements), 'x_min': ranges[0][0], 'x_max': ranges[0][1], 'x_step': (ranges[0][1] - ranges[0][0]) / 10, 'x_format': xformat })