Example #1
0
def transfer(_, **data):
  backup_directory = os.path.join(Path.COMMAND_PATH, '.echomesh-xfer')

  try:
    shutil.rmtree(backup_directory)
  except OSError:
    pass

  directories = data.get('directories', [])
  if '' in directories:
    directories = os.listdir(Path.COMMAND_PATH)

  for directory in directories:
    parent = os.path.dirname(os.path.join(backup_directory, directory))
    MakeDirs.parent_makedirs(parent)
    shutil.move(os.path.join(Path.COMMAND_PATH, directory), parent)

  for f, value in six.iteritems(data.get('files')):
    fname = os.path.join(Path.COMMAND_PATH, f)
    MakeDirs.parent_makedirs(fname)
    with open(fname, 'w') as o:
      o.write(value['contents'])
    os.utime(fname, (value['atime'], value['mtime']))

  if Config.get('delete_backups_after_transfer'):
    try:
      shutil.rmtree(backup_directory)
    except:
      pass
Example #2
0
    def __init__(self, name, suffix):
        if suffix.startswith('.'):
            self.suffix = suffix
        else:
            self.suffix = '.' + suffix

        name_file = DataFile.clean('cache', name)
        self.cachedir = os.path.abspath(os.path.join(*name_file))
        MakeDirs.makedirs(self.cachedir)
        self.manifest_file = os.path.join(self.cachedir, MANIFEST_NAME)
        self.manifest = Merge.merge(*Yaml.read(self.manifest_file))
Example #3
0
  def __init__(self, name, suffix):
    if suffix.startswith('.'):
      self.suffix = suffix
    else:
      self.suffix = '.' + suffix

    name_file = CommandFile.clean('cache', name)
    self.cachedir = os.path.abspath(os.path.join(*name_file))
    MakeDirs.makedirs(self.cachedir)
    self.manifest_file = os.path.join(self.cachedir, MANIFEST_NAME)
    self.manifest = Merge.merge(*Yaml.read(self.manifest_file))
Example #4
0
def _make(path, value):
  path = os.path.expanduser(path)
  exists = os.path.exists(path)
  is_dict = isinstance(value, dict)
  if value is None or is_dict:
    if not exists:
      MakeDirs.makedirs(path)
      _print_path(path)
    if is_dict:
      for k, v in value.items():
        _make(os.path.join(path, k), v)
  elif exists:
    print('Not overwriting existing', path)
  else:
    with open(path, 'w') as f:
      f.write(value)
    _print_path(path)
Example #5
0
def _make(path, value):
    path = os.path.expanduser(path)
    exists = os.path.exists(path)
    is_dict = isinstance(value, dict)
    if value is None or is_dict:
        if not exists:
            MakeDirs.makedirs(path)
            _print_path(path)
        if is_dict:
            for k, v in value.items():
                _make(os.path.join(path, k), v)
    elif exists:
        print('Not overwriting existing', path)
    else:
        with open(path, 'w') as f:
            f.write(value)
        _print_path(path)