Example #1
0
def test_move():
    from metrique.utils import move, rand_chars, remove_file
    dest = tmp_dir
    rel_path_1 = rand_chars(prefix='move')
    path_1 = os.path.join(cache_dir, rel_path_1)
    _path_1 = os.path.join(dest, rel_path_1)
    open(path_1, 'a').close()

    rel_path_2 = rand_chars(prefix='move')
    path_2 = os.path.join(cache_dir, rel_path_2)
    open(path_2, 'a').close()

    paths = (path_1, path_2)

    assert exists(path_1)
    move(path_1, dest)
    assert not exists(path_1)
    move(_path_1, cache_dir)

    assert exists(path_2)
    move(paths, dest)
    assert not any((exists(path_1), exists(path_2)))
    remove_file(paths, force=True)
    remove_file(dest, force=True)
    remove_file(tmp_dir, force=True)

    try:
        move('DOES_NOT_EXST', 'SOMEWHERE')
    except IOError:
        pass
    else:
        assert False, "Moving DOES_NOT_EXIST to SOMEWHERE did not throw an "\
            "exception"

    assert move('DOES_NOT_EXST', 'SOMEWHERE', quiet=True) == []
Example #2
0
def test_move():
    from metrique.utils import move, rand_chars, remove_file
    dest = tmp_dir
    rel_path_1 = rand_chars(prefix='move')
    path_1 = os.path.join(cache_dir, rel_path_1)
    _path_1 = os.path.join(dest, rel_path_1)
    open(path_1, 'a').close()

    rel_path_2 = rand_chars(prefix='move')
    path_2 = os.path.join(cache_dir, rel_path_2)
    open(path_2, 'a').close()

    paths = (path_1, path_2)

    assert exists(path_1)
    move(path_1, dest)
    assert not exists(path_1)
    move(_path_1, cache_dir)

    assert exists(path_2)
    move(paths, dest)
    assert not any((exists(path_1), exists(path_2)))
    remove_file(paths, force=True)
    remove_file(dest, force=True)
    remove_file(tmp_dir, force=True)

    try:
        move('DOES_NOT_EXST', 'SOMEWHERE')
    except IOError:
        pass
    else:
        assert False, "Moving DOES_NOT_EXIST to SOMEWHERE did not throw an "\
            "exception"

    assert move('DOES_NOT_EXST', 'SOMEWHERE', quiet=True) == []
Example #3
0
def trash(args=None):
    named = getattr(args, 'named', None)
    named = '%s-%s' % (named[0], NOW) if named else NOW
    supervisord_terminate()
    celerybeat_terminate()
    celeryd_terminate()
    nginx_terminate()
    postgresql_stop()

    dest = pjoin(TRASH_DIR, 'metrique-%s' % named)
    logger.warn('Trashing existing .metrique -> %s' % dest)
    for f in [ETC_DIR, PIDS_DIR, LOGS_DIR, CACHE_DIR,
              TMP_DIR, POSTGRESQL_PGDATA_PATH]:
        _dest = os.path.join(dest, os.path.basename(f))
        try:
            utils.move(f, _dest)
        except (IOError, OSError) as e:
            logger.error(e)
            continue
    firstboot_glob = os.path.join(PREFIX_DIR, '.firstboot*')
    utils.remove_file(firstboot_glob)
Example #4
0
def trash(args=None):
    named = getattr(args, 'named', None)
    named = '%s-%s' % (named[0], NOW) if named else NOW
    supervisord_terminate()
    celerybeat_terminate()
    celeryd_terminate()
    nginx_terminate()
    postgresql_stop()

    dest = pjoin(TRASH_DIR, 'metrique-%s' % named)
    logger.warn('Trashing existing .metrique -> %s' % dest)
    for f in [
            ETC_DIR, PIDS_DIR, LOGS_DIR, CACHE_DIR, TMP_DIR,
            POSTGRESQL_PGDATA_PATH
    ]:
        _dest = os.path.join(dest, os.path.basename(f))
        try:
            utils.move(f, _dest)
        except (IOError, OSError) as e:
            logger.error(e)
            continue
    firstboot_glob = os.path.join(PREFIX_DIR, '.firstboot*')
    utils.remove_file(firstboot_glob)
Example #5
0
def postgresql_trash():
    postgresql_stop()
    dest = pjoin(TRASH_DIR, 'postgresql-%s' % NOW)
    utils.move(POSTGRESQL_PGDATA_PATH, dest)
    utils.remove_file(POSTGRESQL_FIRSTBOOT_PATH)
    utils.make_dirs(POSTGRESQL_PGDATA_PATH)
Example #6
0
def postgresql_trash():
    postgresql_stop()
    dest = pjoin(TRASH_DIR, 'postgresql-%s' % NOW)
    utils.move(POSTGRESQL_PGDATA_PATH, dest)
    utils.remove_file(POSTGRESQL_FIRSTBOOT_PATH)
    utils.make_dirs(POSTGRESQL_PGDATA_PATH)