def __init__(self, dic, vm_name): dic['results'] = {} self.job_dic = dic self.proceed = True self.job_dic['dest_vm'] = vm_name self.name = '_'.join( [vm_name, dic.get('sample_name')] ) out = '.'.join([self.job_dic.get('dest_vm') + '-sp3', 'v5-msvc10', self.job_dic.get('sample_name'), 'out']) err = '.'.join([self.job_dic.get('dest_vm') + '-sp3', 'v5-msvc10', self.job_dic.get('sample_name'), 'err']) oldmask = os.umask(0007) log_dir = os.path.join(settings.get('LOG_DIR'), dic.get('job')) if not os.path.exists(log_dir): try: os.makedirs(log_dir) except os.error: self.proceed = False os.umask(oldmask) self.job_dic['out_path'] = os.path.join(log_dir, out) self.job_dic['err_path'] = os.path.join(log_dir, err) self.log_path = os.path.join(log_dir, dic.get('err_path')) fileFormat = logging.Formatter(fmt='%(asctime)s:%(name)s:%(levelname)s:%(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') logHandler = logging.FileHandler(self.log_path) logHandler.setLevel(logging.DEBUG) logHandler.setFormatter(fileFormat) self.logger = logging.getLogger(self.name) self.logger.addHandler(logHandler) self.log("Task created, init log")
def setParsed(self, tweet_id, val=1): if SETTINGS.get('debug', False) == True: return False try: query = "UPDATE tracker_tweets SET parsed = %s WHERE tweet_id = %s" self.queryDB(query, (val, tweet_id)) except Exception, e: raise Exception("Setting parsed flag for tweet %s failed: %s" % (tweet_id, e))
def sendTweet(self, message): if SETTINGS.get('tweet', False) is True: try: self.TW.update_status(message) except: self.logError("Tweeting message failed (%s)" % message)
def main(): # Put file arguments in a dictionary: kw = dict([arg.split('=') for arg in sys.argv[1:]]) # Check what we're asked to do: if not 'cmd' in kw: sys.exit('Please supply a command (cmd)!') # Do some basic tasks: if kw['cmd'] in ('cp','copygeo',): copygeo() # Or move on to more complicated things else: # Copy this before reading the arguments settings = SETTINGS.copy() # Extract the experiment id and the config: cwd = os.getcwd() (settings['expid'], settings['config'],) = cwd.split("/")[-2:] settings['scriptdir'] = cwd # Stages to run: try: settings['stages'] = [s.strip() for s in kw['stages'].split(',')] except: #settings['stages'] = ('ungrib','geogrid','metgrid','real','wrf',) settings['stages'] = ('all',) # The duration has to be set try: duration_h = settings['duration_h'] except: try: duration_h = kw['duration_h'] except: duration_h = 24 settings['duration'] = timedelta(hours = int(duration_h)) # Set up: if kw['cmd'] in ('setup',): # Set the anatime: try: anatime = datetime.strptime(kw['anatime'], '%Y%m%d%H') except: sys.exit('Please supply a valid analysis time (anatime=YYYYMMDDHH)!') job = WrfJob( anatime = anatime, **settings ) job.setup() # Submit elif kw['cmd'] in ('sub','submit',): # Set the start date: try: startdate = datetime.strptime(kw['startdate'], '%Y%m%d%H') except: sys.exit('Please supply a valid start date (startdate=YYYYMMDDHH)!') # Set the end date (defaults to start date): try: enddate = datetime.strptime(kw['enddate'], '%Y%m%d%H') except: enddate = startdate commit = None for k in ('c','commit',): try: if kw[k].lower() in ('true','yes',): commit = True break except: pass if commit is None: try: if kw[k].isdigit(): commit = bool(int(kw[k])) break except: pass if commit is None: commit = False # Loop through all the new model runs: anatime = startdate while anatime <= enddate: s = WrfSubmitter( anatime = anatime, commit = commit, **settings ) s.submit() anatime += settings['duration']
def logDebug(self, message): if SETTINGS.get('debug', False) is True: self.log.info('[Debug]: ' + message)
import socket from config import SETTINGS print("Deploy script here") settings = SETTINGS() IPADDRESS = settings.IPADDRESS PORT = settings.PORT conn = socket.socket() conn.connect((IPADDRESS, PORT)) print("Connected") conn.send(bytes('build', encoding="utf8")) conn.close() print("Sent")
# Checks for valid method in all the imported modules then executes it def launch_method(self, method, job_dict): if method in imported_functions: result = imported_functions[method](job_dict) else: print 'Method not found' result = 'Method not found' return result ######################################## # Boiler Plate Main if __name__ == '__main__': host_addr = SETTINGS.get('HOST_ADDR') gateway = SETTINGS.get('LAN_GATEWAY') voodo_port = SETTINGS.get('VOODO_PORT') # Merge the module dicts together for module in imported_modules: imported_functions = dict(imported_functions.items() + module.items()) # Find the host's IP address by creating a test socket, connecting to gateway test_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) if gateway: try: test_socket.connect( (gateway, 65000) ) except socket.error as error: if error.errno == 9: print 'Malformed gateway IP address (LAN_GATEWAY value) in config.py:',gateway print 'Unable to initialize server.' print error