Exemplo n.º 1
0
def reset(yes):
    """
    Remove all the datastores and the database of the current user
    """
    ok = yes or confirm('Do you really want to destroy all your data? (y/n) ')
    if not ok:
        return

    dbpath = os.path.realpath(
        os.path.expanduser(config.get('dbserver', 'file')))

    # user must be able to access and write the databse file to remove it
    if os.path.isfile(dbpath) and os.access(dbpath, os.W_OK):
        if dbserver.get_status() == 'running':
            if config.flag_set('dbserver', 'multi_user'):
                sys.exit('The oq dbserver must be stopped '
                         'before proceeding')
            else:
                logs.dbcmd('stop')
                print('dbserver stopped')

        try:
            os.remove(dbpath)
            print('Removed %s' % dbpath)
        except OSError as exc:
            print(exc, file=sys.stderr)

    # fast way of removing everything
    purge_all(fast=True)  # datastore of the current user
Exemplo n.º 2
0
def check_foreign():
    """
    Check if we the DbServer is the right one
    """
    if not config.flag_set('dbserver', 'multi_user'):
        remote_server_path = logs.dbcmd('get_path')
        if different_paths(server_path, remote_server_path):
            return ('You are trying to contact a DbServer from another' +
                    ' instance (%s)\n' % remote_server_path +
                    'Check the configuration or stop the foreign' +
                    ' DbServer instance')
Exemplo n.º 3
0
 def test_flag_set_with_True(self):
     # flag_set() returns True if the setting is present and equal to True
     self.prepare_config("e", {"v": " True 	 "})
     self.assertTrue(config.flag_set("e", "v"))
Exemplo n.º 4
0
 def test_flag_set_with_text_but_not_true(self):
     # flag_set() returns False if the setting is present but
     # not equal to 'true'
     self.prepare_config("c", {"x": "blah"})
     self.assertFalse(config.flag_set("c", "x"))
Exemplo n.º 5
0
 def test_flag_set_with_number(self):
     # flag_set() returns False if the setting is present but
     # not equal to 'true'
     self.prepare_config("b", {"y": "123"})
     self.assertFalse(config.flag_set("b", "y"))
Exemplo n.º 6
0
 def test_flag_set_with_absent_key(self):
     # flag_set() returns False if the setting
     # is not present in the configuration file.
     self.prepare_config("a")
     self.assertFalse(config.flag_set("a", "z"))