def merge(self, source): """ Merge proposed source configuration file. "source" must be a key of this dictionary, if not, True is returned. If file pointed at source doesn't exist or merge fails, False is returned. """ obj = self.pop(source, None) if obj is None: return True root = ConfigurationFiles.root() source_file = root + source dest_file = root + obj['destination'] self._backup(dest_file) source_file = self._encode_path(source_file) dest_file = self._encode_path(dest_file) try: rename_keep_permissions( source_file, dest_file) except OSError as err: const_debug_write( __name__, "merge, OSError: " "%s, locals: %s" % ( repr(err), locals())) return False return True
def merge(self, source): """ Merge proposed source configuration file. "source" must be a key of this dictionary, if not, True is returned. If file pointed at source doesn't exist or merge fails, False is returned. """ obj = self.pop(source, None) if obj is None: return True root = ConfigurationFiles.root() source_file = root + source dest_file = root + obj['destination'] self._backup(dest_file) source_file = self._encode_path(source_file) dest_file = self._encode_path(dest_file) try: rename_keep_permissions(source_file, dest_file) except OSError as err: const_debug_write( __name__, "merge, OSError: " "%s, locals: %s" % (repr(err), locals())) return False return True
def _load_maybe_add(self, currentdir, item, filepath, number): """ Scan given path and store config file update information if needed. """ try: tofile = item[10:] number = item[5:9] except IndexError as err: const_debug_write(__name__, "load_maybe_add, IndexError: " "%s, locals: %s" % (repr(err), locals())) return try: int(number) except ValueError as err: # not a number const_debug_write(__name__, "load_maybe_add, ValueError: " "%s, locals: %s" % (repr(err), locals())) return tofilepath = os.path.join(currentdir, tofile) # tofile is the target filename now # before adding, determine if we should automerge it if self._load_can_automerge(filepath, tofilepath): if not self._quiet: self._entropy.output( darkred("%s: %s") % (_("Automerging file"), darkgreen(filepath)), importance=0, level="info" ) try: rename_keep_permissions(filepath, tofilepath) except OSError as err: const_debug_write(__name__, "load_maybe_add, OSError: " "%s, locals: %s" % (repr(err), locals())) except IOError as err: const_debug_write(__name__, "load_maybe_add, IOError: " "%s, locals: %s" % (repr(err), locals())) return # store save_filepath = self._strip_root(self._unicode_path(filepath)) obj = { "destination": self._strip_root(self._unicode_path(tofilepath)), "automerge": False, # redundant but backward compat } self[save_filepath] = obj if not self._quiet: self._entropy.output( "%s: %s" % (brown(_("Found update")), self._unicode_path(darkgreen(filepath))), importance=0, level="info", )
def _load_maybe_add(self, currentdir, item, filepath, number): """ Scan given path and store config file update information if needed. """ try: tofile = item[10:] number = item[5:9] except IndexError as err: const_debug_write( __name__, "load_maybe_add, IndexError: " "%s, locals: %s" % (repr(err), locals())) return try: int(number) except ValueError as err: # not a number const_debug_write( __name__, "load_maybe_add, ValueError: " "%s, locals: %s" % (repr(err), locals())) return tofilepath = os.path.join(currentdir, tofile) # tofile is the target filename now # before adding, determine if we should automerge it if self._load_can_automerge(filepath, tofilepath): if not self._quiet: self._entropy.output(darkred("%s: %s") % ( _("Automerging file"), darkgreen(self._unicode_path(filepath)), ), importance=0, level="info") try: rename_keep_permissions(filepath, tofilepath) except OSError as err: const_debug_write( __name__, "load_maybe_add, OSError: " "%s, locals: %s" % (repr(err), locals())) except IOError as err: const_debug_write( __name__, "load_maybe_add, IOError: " "%s, locals: %s" % (repr(err), locals())) return # store save_filepath = self._strip_root(self._unicode_path(filepath)) obj = { 'destination': self._strip_root(self._unicode_path(tofilepath)), 'automerge': False, # redundant but backward compat } self[save_filepath] = obj if not self._quiet: self._entropy.output("%s: %s" % ( brown(_("Found update")), darkgreen(self._unicode_path(filepath)), ), importance=0, level="info")