def csv2youtrack(params): source = dict() for s in ('issues', 'comments', 'attachments'): if params.get(s + '_file'): source[s] = Client(params[s + '_file']) if source: token = params.get('token') if not token and 'token_file' in params: try: with open(params['token_file'], 'r') as f: token = f.read().strip() except (OSError, IOError) as e: print("Cannot load token from file: " + str(e)) sys.exit(1) if token: target = Connection(params['target_url'], token=token) elif 'login' in params: target = Connection(params['target_url'], params.get('login', ''), params.get('password', '')) else: print("You have to provide token or login/password to import data") sys.exit(1) config = CsvYouTrackImportConfig(csvClient.FIELD_NAMES, csvClient.FIELD_TYPES) importer = CsvYouTrackImporter(source, target, config) importer.import_csv() else: print("Nothing to import.")
def generate_mapping_file(issues_csv_filename, mapping_filename=None): if not mapping_filename: mapping_filename = os.path.splitext(issues_csv_filename)[0] + '.json' if os.path.isfile(mapping_filename): print( "Mapping file won't be generated because the file already exists") print(mapping_filename) sys.exit(1) source = Client(issues_csv_filename) mapping_data = dict( __help__="For instructions, see: " + help_url + "#build-mapping-file", field_names=dict({ f: "map_me_to_yt_field" for f in source.get_header() if f.lower() not in ('links', 'tags') }.items() + { "!_mandatory_field__map_it_1": "project_id", "!_mandatory_field__map_it_2": "project_name", "!_mandatory_field__map_it_3": "numberInProject", "!_mandatory_field__map_it_4": "summary", "!_mandatory_field__map_it_5": "created", "!_mandatory_field__map_it_6": "reporterName", "!_yt_field_can_be_skipped_1": "updated", "!_yt_field_can_be_skipped_2": "updaterName", "!_yt_field_can_be_skipped_3": "description", "!_yt_field_can_be_skipped_4": "resolved", "!_yt_field_can_be_skipped_5": "permittedGroup" }.items()), field_types=dict( define_types_here="1 - single value field, * - multi-value field", yt_custom_field_1="enum[1]", yt_custom_field_2="enum[*]", ), csv_field_delimiter=',', csv_value_delimiter=',', date_format_string='%Y-%m-%d %H:%M:%S', use_markdown='no') try: with open(mapping_filename, 'w') as f: json.dump(mapping_data, f, sort_keys=True, indent=4) print("Mapping file has been written to " + mapping_filename) except (IOError, OSError) as e: print("Failed to write mapping file: " + str(e)) sys.exit(1)