def main( argv = None ): #---- get the command-line options --------- opt, args = optionparse.parse( __doc__ ) if opt.options: optionparse.exit() mySets = MySettings() ParseCommandLineArguements( opt, mySets ) print "\n\n===============================================================" print "Starting to <do whatever>: \n" print "----------------------------------------------------------------" print "\n\n" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++ try: # do whatever processing or stuff you need to do here pass except UsageError as err: print >> sys.stderr, err.msg print >> sys.stderr, "error condition" return 2 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++ print "FINISHED " print "===============================================================\n\n"
'SERVER_DATABASE_PASSWORD': '******', 'SERVER_POSTGRESQL_PORT': '10003', 'SERVER_WEBAPP_HOST': '', 'SERVER_WEBAPP_PORT': '', 'SERVER_WEBAPP_SECURE_PORT': '', 'HQ_START_SERVICES': '1', 'AGENT_IS_SECURE': '', 'AGENT_PORT': '10004', 'AGENT_SERVER_USER': '', 'AGENT_SERVER_PASSWORD': '' } }, } if __name__ == '__main__': options, args = optionparse.parse(__doc__) if not args and not options: optionparse.exit() if options.mysqlServer: options.liferayServer = True options.mysql4liferay = True if options.liferaySdk: options.liferayPortal = True options.ant = True if options.all: for option in options.__dict__: if type(getattr(options, option)) == bool and option != 'test': setattr(options, option, True) # copier le mot de passe (ugly, really)
def main(): opt, otherarg = parse(__doc__) if (not opt) or getattr(opt, "usage"): print """ Transfer and transform data from one source to another This module provides functionality for opening one data source,grabbing data that matches selecting criteria, transforming it or clipping it in time and then exporting it to another data source. usage: transfer -i input -s select -o out [-d dest] [-e extent] [-t transformer] -i, --in=input: data store of orginal data records. -s, --selector=select: selection criteria of input data. -o, --out=output: data store where data will be written. -d, --dest=dest: optional,map from selector to the output location in the output data store. -e, --extent=extent: optional, extent within a selected time series, such as a time window (6/26/1929 12:00,12/9/1940 12:00). -t, --trans=transformer: optional, path to the tranformation func to be applied. can be a full path string of existing function provided by vtools package, ,etc. vtools.functions.data_interpolate.interpolate_its or a function defined by user,etc. mypackage.mymodule.myfunctions or mymodule.myfunctions Instance of typical usages: copying all timeseries whose C part is "flow" in file a.dss to a new file b.dss within time window of (4/26/2001 09:30 to 08/30/2004 11:40) with application of Godin filtering: transfer -i a.dss -s C=FLOW -o b.dss -e (4/26/2001T09:30,08/30/2004T11:40) -t vtools.functions.api.godin copying all timeseries whose C part is "flow" in file a.dss to a new file b.dss within time window of (4/26/2001 09:30 to 08/30/2004 11:40) with application of ond day averaging: transfer -i a.dss -s C=FLOW -o b.dss --extent (4/26/2001T09:30,08/30/2004T11:40) -t vtools.functions.api.period_ave interval=1day """ return if not hasattr(opt, "in"): raise ValueError("no source option is given.") if not hasattr(opt, "out"): raise ValueError("no destination option is given.") if not hasattr(opt, "selector"): raise ValueError("no source selection option is given.") if not hasattr(opt, "dest"): raise ValueError("no destination selection option is given.") source = getattr(opt, "in") dest = getattr(opt, "out") sel1 = getattr(opt, "selector") sel2 = getattr(opt, "dest") if hasattr(opt, "trans"): trans = getattr(opt, "trans") else: trans = None #(transname,varlst)=parse_func_args(trans) transname = trans varlst = parse_func_args(otherarg) if hasattr(opt, "extent"): ext = getattr(opt, "extent") else: ext = None print source print dest print sel1 print ext batch_transfer(source,dest=dest,selector=sel1,extent=ext\ ,mapper=sel2,transform=transname,**varlst)
def main(argv=None): if argv is None: argv = sys.argv opt, args = optionparse.parse(__doc__, argv[1:]) params = h2fb.default_params.copy() # Process command line options only used by this module rtf_centered_to_headers = opt.no_centered_to_headers != True del opt.no_centered_to_headers no_zip_output = opt.no_zip_output == True del opt.no_zip_output convertlit_path = opt.convertlit del opt.convertlit lit_clean_temp_dir = opt.no_clean_temp_lit != True del opt.no_clean_temp_lit aggressive_lit_html_clean = opt.aggressive_lit_html_clean == True del opt.aggressive_lit_html_clean # Convert out command line options into something h2fb can handle # convert underscores to hypens, # e.g. "option_something" in to "option-something" (which h2fb expects) opt_dict = {} for temp_param in dir(opt): temp_value = getattr(opt, temp_param) if not temp_param.startswith('_') and not callable(temp_value): temp_key = temp_param.replace( '_', '-' ) ## horrible hack! as "-" were turned into '_' in the argument processor if isinstance(temp_value, unicode): temp_value = str(temp_value) opt_dict[temp_key] = temp_value in_filename = opt_dict['input-file'] del opt_dict['input-file'] out_filename = opt_dict['output-file'] del opt_dict['output-file'] if not out_filename: out_filename = in_filename + '_' + opt_dict[ 'encoding-to'] + '.fb2' ## dumb but quick # Handle .lit files isLIT = False ## FIXME clean up temp directory at end!! if in_filename.lower().endswith('.lit'): isLIT = True if isLIT: from litfuncs import ExtractLIT, clean_lit_str, del_dir, experimental_clean_lit_str lit_clean_html = clean_lit_str if aggressive_lit_html_clean: lit_clean_html = experimental_clean_lit_str ##FIXME get temp dir return... and use it later for clean up temp_lit_directory = out_filename + '__temp_lit_DIR' temp_html_filename = ExtractLIT(in_filename, temp_lit_directory, clit_exe=convertlit_path) print 'temp_html_filename', temp_html_filename in_filename = temp_html_filename # FIXME should be able to dectect this (in h2b??) #params['encoding-from'] = 'UTF-8' params['file-name'] = in_filename # Simply overwrite dictionary for temp_param in opt_dict: params[temp_param] = opt_dict[temp_param] params[ 'detect-verses'] = 0 ## DEBUG, workaround for bug in detect-verses code (line length??), detect-verses makes NO sense for html input files, only makes sense for raw text files (h2fb can handle plain text files) params['skip-empty-lines'] = 0 print 'Input file:', in_filename print 'Output file:', out_filename if compressedfile is None: myfile_open = open else: myfile_open = compressedfile.open_zipfile if compressedfile is None or no_zip_output: myfile_open_for_write = open else: myfile_open_for_write = compressedfile.open_zipfile # start actually processing the file now in_file = myfile_open(in_filename, 'rb') out_file = myfile_open_for_write(out_filename, 'w') ## TODO .LFR format via https://libprs500.kovidgoyal.net/browser/trunk/src/libprs500/ebooks/lrf/parser.py input_text = in_file.read() if isLIT: # .lit (html) input stream clean up input_text = lit_clean_html(input_text) #### DEBUG #~ print '-'*65 #~ print repr(input_text[:24]) #~ print '-'*65 #~ print '='*65 #~ input_text = unicode(input_text,'utf8') #~ print '*'*65 #### DEBUG if input_text.startswith('{\\rtf'): # Looks like we have RTF data not html! import rtf.Rtf2Html #### START temp rtf workaround until Rtf2Html suports e?dash and optional hyphen # RTF input stream clean up ## See bug http://sourceforge.net/tracker/index.php?func=detail&aid=1811128&group_id=103452&atid=634851 ## older rtf spec http://latex2rtf.sourceforge.net/RTF-Spec-1.0.txt # Newline removal ends up without any empty paragraphs (i.e. empty-line tags in FB2) # Fits in with what the input RTF file looks like so I think this is the RIGHT thing to do until RTF lib is fixed. # Also fixes missing bold tags in _some_ cases.... input_text = input_text.replace('\r\n', '') # remove newlines... input_text = input_text.replace('\n', '') # remove newlines... ## TODO remove MAC newlines.....?? for x in ['\emdash', '\\endash']: input_text = input_text.replace(x + ' ', '-') input_text = input_text.replace(x, '-') input_text = input_text.replace('\\-\n', '') # remove, could replace... input_text = input_text.replace('\\-\r\n', '') # remove, could replace... input_text = input_text.replace('\\-', '') # remove, could replace... #### END temp rtf workaround until Rtf2Html suports e?dash and optional hyphen input_text = rtf.Rtf2Html.getHtml(input_text) ## TODO add Centered (or bold) tags as headers? if rtf_centered_to_headers: ## FIXME use beautiful soup (http://www.crummy.com/software/BeautifulSoup/) to find, '<div align='center'>' and convert to H2 input_text = input_text.replace("<div align='center'>", '<h2>') input_text = input_text.replace('</div>', '</h2>') ## TODO add beautiful soup (http://www.crummy.com/software/BeautifulSoup/) clean html before convert support? Possibly put that into h2fb? may help with bad nested bold tags (see unittest, test_nested_emphasis_italic_lesssimple) ## TODO add PDF support?? ## TODO add Table Of Contents generation - if using a decent reader like Haalireader this is not needed. ## TODO zip'd support of html archives that contain images ## BUGFIX filenames in zip's - needed to ensure internal href's are translated correctly, especially for ./thisfile.html#link_name style href's params['data'] = input_text in_file.close() data = h2fb.MyHTMLParser().process(params) out_file.write(data) out_file.close() if isLIT: # .lit temp file clean up if lit_clean_temp_dir: del_dir(temp_lit_directory) return 0
""" Example. usage: %prog [options] args """ import optionparse opt, args = optionparse.parse(__doc__) print opt
def main(argv=None): if argv is None: argv = sys.argv opt, args = optionparse.parse(__doc__, argv[1:]) params = h2fb.default_params.copy() # Process command line options only used by this module rtf_centered_to_headers = opt.no_centered_to_headers != True del opt.no_centered_to_headers no_zip_output = opt.no_zip_output == True del opt.no_zip_output convertlit_path = opt.convertlit del opt.convertlit lit_clean_temp_dir = opt.no_clean_temp_lit != True del opt.no_clean_temp_lit aggressive_lit_html_clean = opt.aggressive_lit_html_clean == True del opt.aggressive_lit_html_clean # Convert out command line options into something h2fb can handle # convert underscores to hypens, # e.g. "option_something" in to "option-something" (which h2fb expects) opt_dict={} for temp_param in dir(opt): temp_value = getattr(opt, temp_param) if not temp_param.startswith('_') and not callable(temp_value): temp_key = temp_param.replace('_', '-') ## horrible hack! as "-" were turned into '_' in the argument processor if isinstance(temp_value, unicode): temp_value=str(temp_value) opt_dict[temp_key] = temp_value in_filename = opt_dict['input-file'] del opt_dict['input-file'] out_filename = opt_dict['output-file'] del opt_dict['output-file'] if not out_filename: out_filename = in_filename + '_' + opt_dict['encoding-to'] + '.fb2' ## dumb but quick # Handle .lit files isLIT=False ## FIXME clean up temp directory at end!! if in_filename.lower().endswith('.lit'): isLIT=True if isLIT: from litfuncs import ExtractLIT, clean_lit_str, del_dir, experimental_clean_lit_str lit_clean_html = clean_lit_str if aggressive_lit_html_clean: lit_clean_html = experimental_clean_lit_str ##FIXME get temp dir return... and use it later for clean up temp_lit_directory = out_filename + '__temp_lit_DIR' temp_html_filename = ExtractLIT(in_filename, temp_lit_directory, clit_exe=convertlit_path) print 'temp_html_filename', temp_html_filename in_filename = temp_html_filename # FIXME should be able to dectect this (in h2b??) #params['encoding-from'] = 'UTF-8' params['file-name'] = in_filename # Simply overwrite dictionary for temp_param in opt_dict: params[temp_param] = opt_dict[temp_param] params['detect-verses'] = 0 ## DEBUG, workaround for bug in detect-verses code (line length??), detect-verses makes NO sense for html input files, only makes sense for raw text files (h2fb can handle plain text files) params['skip-empty-lines'] = 0 print 'Input file:', in_filename print 'Output file:', out_filename if compressedfile is None: myfile_open = open else: myfile_open = compressedfile.open_zipfile if compressedfile is None or no_zip_output: myfile_open_for_write = open else: myfile_open_for_write = compressedfile.open_zipfile # start actually processing the file now in_file = myfile_open(in_filename, 'rb') out_file = myfile_open_for_write(out_filename, 'w') ## TODO .LFR format via https://libprs500.kovidgoyal.net/browser/trunk/src/libprs500/ebooks/lrf/parser.py input_text = in_file.read() if isLIT: # .lit (html) input stream clean up input_text = lit_clean_html(input_text) #### DEBUG #~ print '-'*65 #~ print repr(input_text[:24]) #~ print '-'*65 #~ print '='*65 #~ input_text = unicode(input_text,'utf8') #~ print '*'*65 #### DEBUG if input_text.startswith('{\\rtf'): # Looks like we have RTF data not html! import rtf.Rtf2Html #### START temp rtf workaround until Rtf2Html suports e?dash and optional hyphen # RTF input stream clean up ## See bug http://sourceforge.net/tracker/index.php?func=detail&aid=1811128&group_id=103452&atid=634851 ## older rtf spec http://latex2rtf.sourceforge.net/RTF-Spec-1.0.txt # Newline removal ends up without any empty paragraphs (i.e. empty-line tags in FB2) # Fits in with what the input RTF file looks like so I think this is the RIGHT thing to do until RTF lib is fixed. # Also fixes missing bold tags in _some_ cases.... input_text = input_text.replace('\r\n','') # remove newlines... input_text = input_text.replace('\n','') # remove newlines... ## TODO remove MAC newlines.....?? for x in ['\emdash', '\\endash']: input_text = input_text.replace(x+' ','-') input_text = input_text.replace(x,'-') input_text = input_text.replace('\\-\n','') # remove, could replace... input_text = input_text.replace('\\-\r\n','') # remove, could replace... input_text = input_text.replace('\\-','') # remove, could replace... #### END temp rtf workaround until Rtf2Html suports e?dash and optional hyphen input_text = rtf.Rtf2Html.getHtml(input_text) ## TODO add Centered (or bold) tags as headers? if rtf_centered_to_headers: ## FIXME use beautiful soup (http://www.crummy.com/software/BeautifulSoup/) to find, '<div align='center'>' and convert to H2 input_text = input_text.replace("<div align='center'>",'<h2>') input_text = input_text.replace('</div>','</h2>') ## TODO add beautiful soup (http://www.crummy.com/software/BeautifulSoup/) clean html before convert support? Possibly put that into h2fb? may help with bad nested bold tags (see unittest, test_nested_emphasis_italic_lesssimple) ## TODO add PDF support?? ## TODO add Table Of Contents generation - if using a decent reader like Haalireader this is not needed. ## TODO zip'd support of html archives that contain images ## BUGFIX filenames in zip's - needed to ensure internal href's are translated correctly, especially for ./thisfile.html#link_name style href's params['data'] = input_text in_file.close() data=h2fb.MyHTMLParser().process(params) out_file.write(data) out_file.close() if isLIT: # .lit temp file clean up if lit_clean_temp_dir: del_dir(temp_lit_directory) return 0
def main( argv = None ): #---- get the command-line options --------- opt, args = optionparse.parse( __doc__ ) if opt.options: optionparse.exit() mySets = MySettings() ParseCommandLineArguements( opt, mySets ) print "\n\n===============================================================" print "Starting to send a message: \n" print "----------------------------------------------------------------" print "\n\n" retVal = 0 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++ try: # check to make sure that we have all the parameters if mySets.sender == "" or \ mySets.fromMail == "" or \ mySets.to == "" or mySets.subj == "" or mySets.msg == "": # we didn't get all of the parameters we needed raise NotAllParametersSpecified("Required parameters are missing") # Create the message msg = MIMEText(mySets.msg) msg['To'] = mySets.to msg['Subject'] = mySets.subj # this is the TDA smtp server that I know about #server = smtplib.SMTP('10.134.7.15') server = smtplib.SMTP('prdctavmgwhst03.associatesys.local') server.set_debuglevel(True) # show communication with the server # If we can encrypt this session, do it if server.has_extn('STARTTLS'): server.starttls() server.ehlo() # re-identify ourselves over TLS connection if mySets.password != "": try: print >> sys.stderr, "Password proviced, so attempting to log in!" server.login(mySets.fromMail, mySets.password) except: print >> sys.stderr, "ERROR with logging in." fromMail = mySets.fromMail toMail = mySets.to try: server.sendmail(fromMail, [toMail, fromMail], msg.as_string()) finally: print >> sys.stderr, "Attempting to quit the SMTP server now." server.quit() except (UsageError, NotAllParametersSpecified) as err: print >> sys.stderr, "\n\n" print >> sys.stderr, err.msg print >> sys.stderr, "error condition" print >> sys.stderr, "\n\n" retVal = 2 except smtplib.SMTPRecipientsRefused as err: print >> sys.stderr, "\n\nUnexpected SMTPLib SMTPRecipientsRefused error" print >> sys.stderr, err.recipients print >> sys.stderr, "\n\n" retVal = 4 except smtplib.SMTPException: print >> sys.stderr, "\n\nUnexpected SMTPLib SMTPException error!\n\n" retVal = 50 except smtplib.SMTPServerDisconnected: print >> sys.stderr, "\n\nUnexpected SMTPLib SMTPServerDisconnected error!\n\n" retVal = 51 except smtplib.SMTPResponseException: print >> sys.stderr, "\n\nUnexpected SMTPLib SMTPResponseException error!\n\n" retVal = 52 except smtplib.SMTPSenderRefused: print >> sys.stderr, "\n\nUnexpected SMTPLib SMTPSenderRefused error!\n\n" retVal = 53 except smtplib.SMTPDataError: print >> sys.stderr, "\n\nUnexpected SMTPLib SMTPDataError error!\n\n" retVal = 54 except smtplib.SMTPConnectError: print >> sys.stderr, "\n\nUnexpected SMTPLib SMTPConnectError error!\n\n" retVal = 55 except smtplib.SMTPHeloError: print >> sys.stderr, "\n\nUnexpected SMTPLib SMTPHeloError error!\n\n" retVal =56 except smtplib.SMTPAuthenticationError: print >> sys.stderr, "\n\nUnexpected SMTPLib SMTPAuthenticationError error!\n\n" retVal = 57 except: print >> sys.stderr, "\n\nUnexpected error!\n\n" e = sys.exc_info()[0] print e retVal = 100 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++ print "\n\nFINISHED " print "===============================================================\n\n" return retVal