Пример #1
0
def store_current_settings(c_settings):
    try:
        # Remove certain keys that just shouldn't be saved
        to_save = dict(c_settings)
        for k in ['action', 'verbose', 'dryrun']:
            if k in c_settings:
                to_save.pop(k, None)
        with sh.Rooted(True):
            with open(SETTINGS_FN, 'w') as fh:
                fh.write("# Anvil last used settings\n")
                fh.write(utils.add_header(SETTINGS_FN, utils.prettify_yaml(to_save)))
                fh.flush()
        (uid, gid) = sh.get_suids()
        sh.chown(SETTINGS_FN, uid, gid)
    except Exception as e:
        LOG.debug("Failed writing to %s due to %s", SETTINGS_FN, e)
Пример #2
0
def store_current_settings(settings):
    base_dir = sh.dirname(SETTINGS_FN)
    if not sh.isdir(base_dir):
        # Don't use sh here so that we always
        # read this (even if dry-run)    
        os.makedirs(base_dir)
    try:
        with sh.Rooted(True):
            with open(SETTINGS_FN, 'w') as fh:
                fh.write("# Anvil last used settings\n")
                fh.write(utils.add_header(SETTINGS_FN, utils.prettify_yaml(settings)))
                fh.flush()
        (uid, gid) = sh.get_suids()
        sh.chown_r(base_dir, uid, gid)
    except Exception as e:
        pass
Пример #3
0
def store_current_settings(c_settings):
    try:
        # Remove certain keys that just shouldn't be saved
        to_save = dict(c_settings)
        for k in ['action', 'verbose', 'dryrun']:
            if k in c_settings:
                to_save.pop(k, None)
        with sh.Rooted(True):
            with open(SETTINGS_FN, 'w') as fh:
                fh.write("# Anvil last used settings\n")
                fh.write(
                    utils.add_header(SETTINGS_FN,
                                     utils.prettify_yaml(to_save)))
                fh.flush()
        (uid, gid) = sh.get_suids()
        sh.chown(SETTINGS_FN, uid, gid)
    except Exception as e:
        LOG.debug("Failed writing to %s due to %s", SETTINGS_FN, e)
Пример #4
0
def ensure_anvil_dir():
    if not sh.isdir(ANVIL_DIR):
        with sh.Rooted(True):
            os.makedirs(ANVIL_DIR)
            (uid, gid) = sh.get_suids()
            sh.chown_r(ANVIL_DIR, uid, gid)
Пример #5
0
def ensure_anvil_dir():
    if not sh.isdir(ANVIL_DIR):
        with sh.Rooted(True):
            os.makedirs(ANVIL_DIR)
            (uid, gid) = sh.get_suids()
            sh.chown_r(ANVIL_DIR, uid, gid)