def handle_db(self, args): database, table = self._get_db_settings() if args.db_command == "create": home = self.config.get('server', 'home') admin.setup_db(database, table, home) elif args.db_command == "optimize": admin.optimize_db(self.context, database, table) elif args.db_command == "rebuild": admin.rebuild_db_indexes(database, table) elif args.db_command == "clean": force = args.accept_changes if not force: msg = "This will delete all records! Continue [Y/n] " if raw_input(msg) == 'Y': force = True if force: admin.delete_records(self.context, database, table)
print 'ERROR: -s /path/to/file.xsd is a required argument' sys.exit(12) if COMMAND == 'setup_db': try: admin.setup_db(DATABASE, TABLE, HOME) except Exception as err: print err print 'ERROR: DB creation error. Database tables already exist' print 'Delete tables or database to reinitialize' elif COMMAND == 'load_records': admin.load_records(CONTEXT, DATABASE, TABLE, XML_DIRPATH, RECURSIVE, FORCE_CONFIRM) elif COMMAND == 'export_records': admin.export_records(CONTEXT, DATABASE, TABLE, XML_DIRPATH) elif COMMAND == 'rebuild_db_indexes': admin.rebuild_db_indexes(DATABASE, TABLE) elif COMMAND == 'optimize_db': admin.optimize_db(CONTEXT, DATABASE, TABLE) elif COMMAND == 'refresh_harvested_records': admin.refresh_harvested_records(CONTEXT, DATABASE, TABLE, URL) elif COMMAND == 'gen_sitemap': admin.gen_sitemap(CONTEXT, DATABASE, TABLE, URL, OUTPUT_FILE) elif COMMAND == 'post_xml': print admin.post_xml(CSW_URL, XML, TIMEOUT) elif COMMAND == 'get_sysprof': print admin.get_sysprof() elif COMMAND == 'validate_xml': admin.validate_xml(XML, XSD) elif COMMAND == 'delete_records': if not FORCE_CONFIRM: if raw_input('This will delete all records! Continue? [Y/n] ') == 'Y':
sys.exit(12) if COMMAND == 'setup_db': try: admin.setup_db(DATABASE, TABLE, HOME) except Exception as err: print(err) print('ERROR: DB creation error. Database tables already exist') print('Delete tables or database to reinitialize') elif COMMAND == 'load_records': admin.load_records(CONTEXT, DATABASE, TABLE, XML_DIRPATH, RECURSIVE, FORCE_CONFIRM) elif COMMAND == 'export_records': admin.export_records(CONTEXT, DATABASE, TABLE, XML_DIRPATH) elif COMMAND == 'rebuild_db_indexes': admin.rebuild_db_indexes(DATABASE, TABLE) elif COMMAND == 'optimize_db': admin.optimize_db(CONTEXT, DATABASE, TABLE) elif COMMAND == 'refresh_harvested_records': admin.refresh_harvested_records(CONTEXT, DATABASE, TABLE, URL) elif COMMAND == 'gen_sitemap': admin.gen_sitemap(CONTEXT, DATABASE, TABLE, URL, OUTPUT_FILE) elif COMMAND == 'post_xml': print(admin.post_xml(CSW_URL, XML, TIMEOUT)) elif COMMAND == 'get_sysprof': print(admin.get_sysprof()) elif COMMAND == 'validate_xml': admin.validate_xml(XML, XSD) elif COMMAND == 'delete_records': if not FORCE_CONFIRM: if input('This will delete all records! Continue? [Y/n] ') == 'Y':
def run(self, argv): if len(argv) == 0: grass.error('Nothing to do. Set args') return print argv try: OPTS, ARGS = getopt.getopt(argv, 'c:f:ho:p:ru:x:s:t:y') except getopt.GetoptError as err: grass.error('\nERROR: %s' % err) #print usage() for o, a in OPTS: if o == '-c': self.COMMAND = a if o == '-f': self.CFG = a if o == '-o': self.OUTPUT_FILE = a if o == '-p': self.XML_DIRPATH = a if o == '-r': self.RECURSIVE = True if o == '-u': self.CSW_URL = a if o == '-x': self.XML = a if o == '-t': self.TIMEOUT = int(a) if o == '-y': self.FORCE_CONFIRM = True if self.CFG is None and self.COMMAND not in ['post_xml']: print 'ERROR: -f <cfg> is a required argument' if self.COMMAND not in ['post_xml']: SCP = ConfigParser.SafeConfigParser() SCP.readfp(open(self.CFG)) self.DATABASE = SCP.get('repository', 'database') self.URL = SCP.get('server', 'url') self.HOME = SCP.get('server', 'home') self.METADATA = dict(SCP.items('metadata:main')) try: self.TABLE = SCP.get('repository', 'table') except ConfigParser.NoOptionError: self.TABLE = 'records' if self.COMMAND == 'setup_db': try: admin.setup_db(self.DATABASE, self.TABLE, self.HOME) except Exception as err: print err print 'ERROR: DB creation error. Database tables already exist' print 'Delete tables or database to reinitialize' elif self.COMMAND == 'load_records': admin.load_records(self.CONTEXT, self.DATABASE, self.TABLE, self.XML_DIRPATH, self.RECURSIVE, self.FORCE_CONFIRM) elif self.COMMAND == 'export_records': admin.export_records(self.CONTEXT, self.DATABASE, self.TABLE, self.XML_DIRPATH) elif self.COMMAND == 'rebuild_db_indexes': admin.rebuild_db_indexes(self.DATABASE, self.TABLE) elif self.COMMAND == 'optimize_db': admin.optimize_db(self.CONTEXT, self.DATABASE, self.TABLE) elif self.COMMAND == 'refresh_harvested_records': admin.refresh_harvested_records(self.CONTEXT, self.DATABASE, self.TABLE, self.URL) elif self.COMMAND == 'gen_sitemap': admin.gen_sitemap(self.CONTEXT, self.DATABASE, self.TABLE, self.URL, self.OUTPUT_FILE) elif self.COMMAND == 'post_xml': grass.message(admin.post_xml(self.CSW_URL, self.XML, self.TIMEOUT)) elif self.COMMAND == 'delete_records': admin.delete_records(self.CONTEXT, self.DATABASE, self.TABLE)