示例#1
0
def clear_records():
    '''
    Function that clears records for both database and search backend.
    '''
    registry.REGISTRY_INDEX_NAME = 'test'
    yield
    es_client = rawes.Elastic(registry.REGISTRY_SEARCH_URL)
    es_client.delete(registry.REGISTRY_INDEX_NAME)
    context = config.StaticContext()
    delete_records(context, registry.PYCSW['repository']['database'],
                   registry.PYCSW['repository']['table'])
示例#2
0
def test_clear_records(client):
    response = client.delete('/catalog/{0}/csw'.format(catalog_slug))
    assert 200 == response.status_code
    assert 'removed' in response.content.decode('utf-8')

    # Delete records in pycsw database.
    context = config.StaticContext()
    delete_records(context, registry.PYCSW['repository']['database'],
                   registry.PYCSW['repository']['table'])

    # Delete a catalog that has not been created previosuly.
    response = client.delete('/catalog/boom/csw')
    assert 404 == response.status_code
    assert 'does not exist' in response.content.decode('utf-8')
示例#3
0
def test_clear_records(client):
    response = client.delete('/catalog/{0}/csw'.format(catalog_slug))
    assert 200 == response.status_code
    assert 'removed' in response.content.decode('utf-8')

    # Delete records in pycsw database.
    context = config.StaticContext()
    delete_records(context,
                   registry.PYCSW['repository']['database'],
                   registry.PYCSW['repository']['table'])

    # Delete a catalog that has not been created previosuly.
    response = client.delete('/catalog/boom/csw')
    assert 404 == response.status_code
    assert 'does not exist' in response.content.decode('utf-8')
示例#4
0
文件: pycsw.py 项目: dpawasi/oim-cms
 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)
示例#5
0
 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)
示例#6
0
    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':
            FORCE_CONFIRM = True
    if FORCE_CONFIRM:
        admin.delete_records(CONTEXT, DATABASE, TABLE)

print 'Done'
示例#7
0
        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':
            FORCE_CONFIRM = True
    if FORCE_CONFIRM:
        admin.delete_records(CONTEXT, DATABASE, TABLE)

print('Done')
示例#8
0
    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)