def _root__execute_(): file_input_master = root_path_file_master.get() file_input_addcsv = root_path_file_addcsv.get() type_input = root_choose_in.get() type_output = root_chooseext.get() name_input_master = _basenameNotExt(file_input_master) name_input_addcsv = _basenameNotExt(file_input_addcsv) name_output = _basenameFullPathNotExt(file_input_master) name_output = ''.join([name_output, '+merged+', name_input_addcsv]) #CZ#file_output_csv = '.'.join([name_output, TYPE_OUT_csv]) if name_input != '' else CHAR_STD_INOUT #CZ#file_output_xls = '.'.join([name_output, TYPE_OUT_xls]) if name_input != '' else CHAR_STD_INOUT file_output_csv = '.'.join([ name_output, TYPE_OUT_csv ]) if name_input_master != '' else CHAR_STD_INOUT #CZ#file_output = None file_output = None if (args.file_output == CHAR_STD_INOUT) else args.file_output file_output = file_output_csv if (file_output is None) and ( type_output == TYPE_OUT_csv) else file_output #CZ#file_output = file_output_xls if (file_output is None) and (type_output == TYPE_OUT_xls) else file_output type_input = _root_combo_get(root_combo_out, type_input) self_type_input.set(type_input) self_file_input_master.set(file_input_master) self_file_input_addcsv.set(file_input_addcsv) self_name_input_master.set(name_input_master) self_name_input_addcsv.set(name_input_addcsv) self_file_output.set(file_output) self_type_output.set(type_output) if _trim(name_input_master) == '': logs_error('Choose csv file Master, please!') return if _trim(name_input_addcsv) == '': logs_error('Choose csv file AddCSV, please!') return if not _fileExist(file_input_master): logs_error("File Master '%s' not exist!" % file_input_master) return if not _fileExist(file_input_addcsv): logs_error("File AddCSV '%s' not exist!" % file_input_addcsv) return if _fileExist(file_output): #CZ#logs_error("File output '%s' exist!\n\nDelete or move/rename and retry..." % file_output) #CZ#return result = askyesno( 'question', "File output '%s' exist!\n\nOverwrite?" % file_output) if result == False: return #CZ#else: #CZ# logs_info("File output '%s' set overwrite!" % file_output) manipulate()
def init_check(): if args.verbose: logs.info(LINE_SEPARATOR) #-------------------------------------------------------------------------- if login_credential_servicej: if not _fileExist(servicej): logs.error('File %s not exist!' % servicej) if login_credential_accountj: if not _fileExist(accountj): logs.error('File %s not exist!' % accountj)
def read_filein(): #txt_filename = file_input txt_filename = self_file_input.get() filein = None std_in = False if txt_filename == CHAR_STD_INOUT: filein = sys.stdin std_in = True logs.info('Read txt rows on STDIN:') else: if not _fileExist(txt_filename): logs_error("Can't read file '%s', exist?" % txt_filename) try: filein = open(txt_filename, 'r') logs.info('Read on file txt: %s' % txt_filename) except: filein = sys.stdin std_in = True logs.info('File txt not set, read on STDIN:') if std_in: logs.info(LINE_PARTITION) #csv_lines = list(csv.reader(filein, delimiter=csv_delimiter)) txt_lines = filein.readlines() if std_in: logs.info(LINE_PARTITION) if args.debug >= 3: logs.info('txt values=') for values in txt_lines: logs.info(values) return (txt_lines)
def _root_translate(): file_input = root_path_file.get() type_input = root_choose_in.get() type_output = root_chooseext.get() name_input = _basenameNotExt(file_input) name_output = _basenameFullPathNotExt(file_input) file_output_csv = '.'.join([name_output, TYPE_OUT_csv ]) if name_input != '' else CHAR_STD_INOUT file_output_xls = '.'.join([name_output, TYPE_OUT_xls ]) if name_input != '' else CHAR_STD_INOUT file_output = None file_output = file_output_csv if (file_output is None) and ( type_output == TYPE_OUT_csv) else file_output file_output = file_output_xls if (file_output is None) and ( type_output == TYPE_OUT_xls) else file_output type_input = _root_combo_get(root_combo_out, type_input) self_type_input.set(type_input) self_file_input.set(file_input) self_name_input.set(name_input) self_file_output.set(file_output) self_type_output.set(type_output) if _trim(name_input) == '': logs_info('Choose text file report, please!') return if not _fileExist(file_input): logs_info("File report '%s' not exist!" % file_input) return manipulate()
def __init__(self): conf = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation()) if not _fileExist(file_conf): print("File configuration %s not found!" % (file_conf)) conf = None else: conf.read(file_conf) conf = self.parser_conf_init(conf, 'Os', 'path_join', _pathSep()) conf = self.parser_conf_init(conf, 'Os', 'path_home', _pathExpanduser('~')) self.conf = conf
def read_filein(file_csv): #csv_filename = file_input_master #csv_filename = self_file_input_master.get() csv_filename = file_csv filein = None std_in = False if csv_filename == CHAR_STD_INOUT: filein = sys.stdin std_in = True logs.info('Read csv rows on STDIN:') else: if not _fileExist(csv_filename): logs_error("Can't read file '%s', exist?" % csv_filename) try: filein = open(csv_filename, 'r') logs.info('Read on file csv: %s' % csv_filename) except: filein = sys.stdin std_in = True logs.info('File csv not set, read on STDIN:') if std_in: logs.info(LINE_PARTITION) #CZ#txt_lines = filein.readlines() csv_lines = list(csv.reader(filein, delimiter=csv_delimiter)) if std_in: logs.info(LINE_PARTITION) if args.debug >= 3: logs.info('csv values=') #CZ# for values in txt_lines: #CZ# logs.info(values) #logs_info('\n'.join(str(values) for values in csv_lines)) logs_info(_joinChar(str(values) for values in csv_lines)) #CZ#return(txt_lines) return (csv_lines)
def __init__(self, name=None): if not _fileExist(file_logs): print("File logger %s not found!" % (file_logs)) self.logs = _log(name, file_logs)
# curl -u "url_username:url_password" -F "file=@path_file" -H "X-BOS-MFT=1" -H "X-BOS-MFT-CLIENTID=flow_name" url_address # #______________________________________________________________________________________________________________________________________________________________# # # # curl -u "%MFT_auth%" -F "file=@%MFT_file%" -H "X-BOS-MFT:1" -H "X-BOS-MFT-CLIENTID:%MFT_flow%" "%MFT_endp%" # # curl -u "tstmft0:tstmft0" -F "file=@C:\tmp\TST.txt" -H "X-BOS-MFT:1" -H "X-BOS-MFT-CLIENTID:TSTMFT0" "http://apps.payroll.it/bos-mft-server/mft" # #______________________________________________________________________________________________________________________________________________________________# exitcode = None messages = None move_file = None send_file = _pathJoin([ path_save, ('%s_send2payroll_%s' % (flow_name, _basename(path_file))) ]) if _fileExist(send_file): messages = _message_check % send_file logs.info(messages) move_file = send_file else: if _fileExist(path_file): try: #CZ#messages = _message_check % path_file ; logs.info(messages) _fileMove(path_file, send_file) move_file = path_file except Exception as e: logs.warning(str(e)) messages = _message_moved % path_file
def main(): try: send_email = _email() send_email._setMailSmtp(email__smtp__) send_email._setMailAuthUser(emailAuthUser) send_email._setMailAuthPswd(emailAuthPswd) send_email._setMailSubject(email_subject) #CZ#send_email._setMailMessage (email_message) send_email._setMailFrom(email__from__) send_email._setMailTo(email___to___) send_email._setMailCc(email___cc___) send_email._setMailCcn(email___ccn__) send_email._setMailHtmlFontSize(emailfontsize) loop_count = 1 while (True): _clear() tag_on_log = "|%05s|" % (loop_count) logs.info( "%s========================================================================" % (tag_on_log)) try: logs.info("%s Scarico file %s in corso..." % (tag_on_log, url_file_name)) _wgetFile(url_path_file, tag_down_name) logs.info("%s Scarico file %s completato!" % (tag_on_log, url_file_name)) except: logs.info("(*** USCITA MENTRE SCARICAVO IL FILE ***) *_*") exc_type, exc_value, exc_traceback = sys.exc_info() logs.traceback(exc_traceback) logs.error(exc_value) load_file = True if _fileExist(tag_load_name): logs.info("%s Confronto file %s => %s in corso..." % (tag_on_log, tag_down_name, tag_load_name)) load_file = not cmp(tag_down_name, tag_load_name) logs.info("%s Confronto file %s => %s completato!" % (tag_on_log, tag_down_name, tag_load_name)) if load_file: logs.info( "%s I files sembrano diversi, procedo con il caricamento... :-|" % (tag_on_log)) else: logs.info("%s I files sembrano uguali :-)" % (tag_on_log)) else: logs.info("%s Copio file %s => %s in corso..." % (tag_on_log, tag_down_name, tag_load_name)) _copy2(tag_down_name, tag_load_name) logs.info("%s Copio file %s => %s completato!" % (tag_on_log, tag_down_name, tag_load_name)) if load_file: commands_exit = 0 commands_logs = '' if commands_exec: return_code = 0 return_stdo = '' return_stde = '' try: logs.info("%s Esecuzione comando [%s] in corso..." % (tag_on_log, commands_open)) #CZ#(return_code) = _os._system(commands_open) (return_code, return_stdo, return_stde) = _popen(commands_open) logs.info("%s Esecuzione comando [%s] completato!" % (tag_on_log, commands_open)) except: logs.info( "%s Esecuzione comando [%s] con errori! :-(" % (tag_on_log, commands_open)) exc_type, exc_value, exc_traceback = sys.exc_info() return_code = 1 return_stde = str(exc_value) logs.traceback(exc_traceback) logs.warning(exc_value) #CZ#logs.error(exc_value) commands_exit = return_code if return_stdo != '': commands_logs = "\n".join((commands_logs, return_stdo)) if return_stde != '': commands_logs = "\n".join((commands_logs, return_stde)) else: logs.info("%s Esecuzione %s disabilitata. :-|" % (tag_on_log, commands_open)) ############################################################### ''' logs.warning("return_code: %s" % return_code) logs.warning("return_stdo: %s" % return_stdo) logs.warning("return_stde: %s" % return_stde) sys.exit(0) # mail__body__ = email_message % (commands_logs ,commands_exit ,'<file.read()>') logs.warning(mail__body__) sys.exit(0) ''' ############################################################### email_notify_ = False if email_notify_: try: with open(tag_load_name) as file: email__body__ = email_message % ( commands_logs, commands_exit, file.read()) file.close() logs.info("%s Invio notifica email in corso..." % (tag_on_log)) send_email._setMailMessage(email__body__) send_email._send() logs.info("%s Invio notifica email completata!" % (tag_on_log)) except: logs.info("%s Invio notifica email con errori! :-(" % (tag_on_log)) exc_type, exc_value, exc_traceback = sys.exc_info() logs.traceback(exc_traceback) logs.warning(exc_value) else: logs.info("%s Invio notifica email disabilitata. :-|" % (tag_on_log)) try: logs.info("%s ...aspetto %s secondi..." % (tag_on_log, time_for_loop)) sleep(time_for_loop) loop_count += 1 except: logs.warning("(*** USCITA MENTRE ASPETTAVO ***) ^_*") exc_type, exc_value, exc_traceback = sys.exc_info() logs.traceback(exc_traceback) logs.error(exc_value) except: logs.warning("(*** USCITA ANOMALA ***) o_O") exc_type, exc_value, exc_traceback = sys.exc_info() logs.traceback(exc_traceback) logs.error(exc_value) sys.exit(0)