def gerapadrao(args): script, collection_acron = gerapadrao_get_inputs(args) errors = gerapadrao_validate_inputs(collection_acron) if len(errors) > 0: print(errors) else: config = xc.get_configuration(collection_acron) if config is not None: mailer = xc.get_mailer(config) start_time = datetime.now().isoformat()[11:11+5].replace(':', '') log_filename = './gerapadrao_' + collection_acron + '-' + start_time + '.log' if config.is_enabled_gerapadrao: if is_unblocked_gerapadrao(config.gerapadrao_permission_file): config.update_title_and_issue() scilista_content = consume_collection_scilista(config.collection_scilista) if scilista_content is None: print(config.collection_scilista + ' is empty') else: scilista_content = sort_scilista(scilista_content) print(scilista_content) scilista_items = scilista_content.split('\n') print(scilista_items) block_gerapadrao(config.gerapadrao_permission_file) open(config.gerapadrao_scilista, 'w').write(scilista_content) gerapadrao_cmd = gerapadrao_command(config.gerapadrao_proc_path, config.gerapadrao_permission_file) if mailer is not None: mailer.send_message(config.email_to, config.email_subject_gerapadrao.replace('Gerapadrao', 'Gerapadrao ' + start_time + ' '), config.email_text_gerapadrao + scilista_content) open(log_filename, 'a+').write(datetime.now().isoformat() + ' ' + start_time + ' - inicio gerapadrao\n') open(log_filename, 'a+').write(gerapadrao_cmd) open(log_filename, 'a+').write(scilista_content) os.system(gerapadrao_cmd) #clean_collection_scilista(config.collection_scilista) open(log_filename, 'a+').write(datetime.now().isoformat() + ' ' + start_time + ' - fim gerapadrao\n') if config.is_enabled_transference: open(log_filename, 'a+').write(datetime.now().isoformat() + ' ' + start_time + ' - inicio transf bases\n') transfer_website_bases(config.local_web_app_path + '/bases', config.transference_user, config.transference_servers, config.remote_web_app_path + '/bases', log_filename) open(log_filename, 'a+').write(datetime.now().isoformat() + ' ' + start_time + ' - fim transf bases\n') open(log_filename, 'a+').write(datetime.now().isoformat() + ' ' + start_time + ' - inicio transf files\n') transfer_website_files(config.local_web_app_path, config.transference_user, config.transference_servers, config.remote_web_app_path, scilista_items, log_filename) open(log_filename, 'a+').write(datetime.now().isoformat() + ' ' + start_time + ' - fim transf files\n') if mailer is not None: mailer.send_message(config.email_to, config.email_subject_website_update.replace('Gerapadrao', 'Gerapadrao ' + start_time + ' '), config.email_text_website_update + scilista_content) else: print('gerapadrao is running. Wait ...') if mailer is not None: if os.path.isfile(config.collection_scilista): mailer.send_message(config.email_to_adm, 'gerapadrao is busy', open(config.collection_scilista, 'r').read())
def receive_xml_files(args): script, collection_acron = xml_receipt_get_inputs(args) errors = xml_receipt_validate_inputs(collection_acron) if len(errors) > 0: print(errors) else: config = xc.get_configuration(collection_acron) if config is not None: files, log = download_packages(config) if len(files) > 0: mailer = xc.get_mailer(config) if mailer is not None: mailer.send_message(config.email_to, config.email_subject_packages_receipt, config.email_text_packages_receipt + '\n' + log)
def execute_converter(package_paths, collection_name=None): collection_names = {} collection_acron = collection_names.get(collection_name) if collection_acron is None: collection_acron = collection_name config = xc.get_configuration(collection_acron) if config is not None: prepare_env(config) invalid_pkg_files = [] mailer = xc.get_mailer(config) if package_paths is None: package_paths, invalid_pkg_files = queue_packages(config.download_path, config.temp_path, config.queue_path, config.archive_path) if package_paths is None: package_paths = [] if not isinstance(package_paths, list): package_paths = [package_paths] for package_path in package_paths: package_folder = os.path.basename(package_path) utils.display_message(package_path) scilista_items = [] xc_status = 'interrupted' stats_msg = '' report_location = None try: scilista_items, xc_status, stats_msg, report_location = convert_package(package_path) except Exception as e: if config.queue_path is not None: fs_utils.delete_file_or_folder(package_path) if config.email_subject_invalid_packages is not None: send_message(mailer, config.email_to_adm, '[Step 1]' + config.email_subject_invalid_packages, config.email_text_invalid_packages + '\n' + package_folder + '\n' + str(e)) if len(package_paths) == 1: raise print(scilista_items) try: acron, issue_id = scilista_items[0].split(' ') if xc_status in ['accepted', 'approved']: if config.collection_scilista is not None: open(config.collection_scilista, 'a+').write('\n'.join(scilista_items) + '\n') if config.is_enabled_transference: transfer_website_files(acron, issue_id, config.local_web_app_path, config.transference_user, config.transference_servers, config.remote_web_app_path) if report_location is not None: if config.email_subject_package_evaluation is not None: results = ' '.join(EMAIL_SUBJECT_STATUS_ICON.get(xc_status, [])) + ' ' + stats_msg link = config.web_app_site + '/reports/' + acron + '/' + issue_id + '/' + os.path.basename(report_location) report_location = '<html><body>' + html_reports.link(link, link) + '</body></html>' transfer_report_files(acron, issue_id, config.local_web_app_path, config.transference_user, config.transference_servers, config.remote_web_app_path) send_message(mailer, config.email_to, config.email_subject_package_evaluation + u' ' + package_folder + u': ' + results, report_location) except Exception as e: if config.email_subject_invalid_packages is not None: send_message(mailer, config.email_to_adm, '[Step 2]' + config.email_subject_invalid_packages, config.email_text_invalid_packages + '\n' + package_folder + '\n' + str(e)) if len(package_paths) == 1: print('exception as finishing') raise if len(invalid_pkg_files) > 0: if config.email_subject_invalid_packages is not None: send_message(mailer, config.email_to, config.email_subject_invalid_packages, config.email_text_invalid_packages + '\n'.join(invalid_pkg_files)) utils.display_message(_('finished'))