def create_db(self, catalogue_filename, fmt, db_filename): cat_db = CatalogueDatabase(filename=db_filename) parser = FMT_MAP[fmt] self.dock.enableBusyCursor() try: with open(catalogue_filename, "rb") as cat_file: store_events(parser, cat_file, cat_db) self.dock.update_selectDbComboBox(db_filename) finally: self.dock.disableBusyCursor() return cat_db
def import_catalogue(self, format): if format == "isf": file_type = 'Isf file (*.txt)' elif format == "iaspei": file_type = 'Iaspei file (*.csv)' self.import_file_path = unicode(QFileDialog.getOpenFileName( self.iface.mainWindow(), 'Select Catalogue file', QDir.homePath(), file_type)) self.save_file_path = unicode(QFileDialog.getSaveFileName( self.iface.mainWindow(), 'Save Catalogue file into', QDir.homePath(), file_type)) self.cat_db = CatalogueDatabase(filename=self.save_file_path) with open(self.import_file_path, 'rb') as cat_file: store_events(FMT_MAP[format], cat_file, self.cat_db)
def load_catalog(): CatalogueDatabase.reset_singleton() cat = CatalogueDatabase(memory=True) cat.recreate() store_events(V1, file(in_data_dir('isc-query-small.html')), cat) return cat
input_file = arguments.input_file[0] fmt_file = arguments.format_type[0] fname = (os.path.abspath(input_file) if os.path.exists(input_file) else None) cat_fmt = (fmt_file.lower() if fmt_file.lower() in ['isf', 'iaspei'] else None) if fname is None: print 'Can\'t find the provided input file' sys.exit(-1) if cat_fmt is None: print 'Format %s is not supported' % fmt_file sys.exit(-1) return fname, cat_fmt if __name__ == '__main__': parser = build_cmd_parser() if len(sys.argv) == 1: parser.print_help() else: args = parser.parse_args() filename, cat_format = check_args(args) cat_dbname = (args.db_filename[0] if isinstance(args.db_filename, list) else args.db_filename) with open(filename, 'r') as cat_file: cat_db = CatalogueDatabase(filename=cat_dbname, drop=args.drop_database) store_events(fmt_map[cat_format], cat_file, cat_db) sys.exit(0)