Example #1
0
 def stringify(self, fn=None):
     contents = ''
     with io.BytesIO() as outputstream:
         self.write(outputstream)
         outputstream.flush()
         contents = utils.add_header(fn, outputstream.getvalue())
     return contents
Example #2
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 open("/etc/anvil/settings.yaml", "w") as fh:
            fh.write("# Anvil last used settings\n")
            fh.write(utils.add_header("/etc/anvil/settings.yaml", utils.prettify_yaml(to_save)))
            fh.flush()
    except Exception as e:
        LOG.debug("Failed writing to %s due to %s", "/etc/anvil/settings.yaml", e)
Example #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']:
            if k in c_settings:
                to_save.pop(k, None)
        buf = six.StringIO()
        buf.write("# Anvil last used settings\n")
        buf.write(utils.add_header(SETTINGS_FILE,
                                   utils.prettify_yaml(to_save),
                                   adjusted=sh.isfile(SETTINGS_FILE)))
        sh.write_file(SETTINGS_FILE, buf.getvalue())
    except Exception as e:
        LOG.debug("Failed writing to %s due to %s", SETTINGS_FILE, e)
Example #4
0
def store_current_settings(c_settings):
    # Remove certain keys that just shouldn't be saved
    to_save = dict(c_settings)
    for k in ['action', 'verbose']:
        if k in c_settings:
            to_save.pop(k, None)
    buf = six.StringIO()
    buf.write("# Anvil last used settings\n")
    buf.write(
        utils.add_header(SETTINGS_FILE,
                         utils.prettify_yaml(to_save),
                         adjusted=sh.isfile(SETTINGS_FILE)))
    try:
        sh.write_file(SETTINGS_FILE, buf.getvalue())
    except OSError as e:
        LOG.warn("Failed writing to %s due to %s", SETTINGS_FILE, e)
Example #5
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 open("/etc/anvil/settings.yaml", 'w') as fh:
            fh.write("# Anvil last used settings\n")
            fh.write(
                utils.add_header("/etc/anvil/settings.yaml",
                                 utils.prettify_yaml(to_save)))
            fh.flush()
    except Exception as e:
        LOG.debug("Failed writing to %s due to %s", "/etc/anvil/settings.yaml",
                  e)
Example #6
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
Example #7
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)
Example #8
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)
Example #9
0
 def _update_passwords(self):
     if not self.store_passwords:
         return
     if not self.passwords.cache:
         return
     who_update = []
     for fn in self.password_files:
         if sh.isfile(fn):
             who_update.append(fn)
     if not who_update:
         who_update.append(self.default_password_file)
     who_done = []
     for fn in who_update:
         if sh.isfile(fn):
             contents = utils.load_yaml(fn)
         else:
             contents = {}
         contents.update(self.passwords.cache)
         sh.write_file(fn, utils.add_header(fn, utils.prettify_yaml(contents)))
         who_done.append(fn)
     utils.log_iterable(who_done,
                        header="Updated/created %s password files" % len(who_done),
                        logger=LOG)
Example #10
0
 def stringify(self, fn=None):
     outputstream = StringIO()
     self.write(outputstream)
     contents = utils.add_header(fn, outputstream.getvalue())
     return contents
Example #11
0
 def stringify(self, fn=None):
     outputstream = StringIO()
     self.write(outputstream)
     contents = utils.add_header(fn, outputstream.getvalue())
     return contents