Example #1
0
File: Context.py Project: azag0/caf
    def get_hashes(self):
        """Get hashes of task's dependencies.

        Dependencies consist of all files and on locks of children.
        """
        with cd(self.path):
            hashes = {}
            for dirpath, dirnames, filenames in os.walk('.'):
                if dirpath == '.':
                    dirnames[:] = [name for name in dirnames
                                   if name not in ['.caf'] + list(self.links)]
                for name in filenames:
                    filepath = Path(dirpath)/name
                    if filepath.is_symlink():
                        target = os.readlink(str(filepath))
                        if Path(target).is_absolute():
                            error('Cannot link to absolute paths in tasks')
                        if str(filepath) in self.files:
                            with cd(filepath.parent):
                                hashes[str(filepath)] = get_file_hash(Path(target))
                        else:
                            hashes[str(filepath)] = target
                    else:
                        make_nonwritable(filepath)
                        hashes[str(filepath)] = get_file_hash(filepath)
            for linkname in self.links:
                hashes[linkname] = get_file_hash(Path(linkname)/'.caf/lock')
        return hashes
Example #2
0
File: Context.py Project: azag0/caf
 def store_link_text(self, text, target, label=None):
     h = hashlib.new(hashf)
     h.update(text.encode())
     texthash = h.hexdigest()
     cellarpath = self.ctx.cellar/str_to_path(texthash)
     if not cellarpath.is_file():
         if label is True:
             info('Stored new file "{}"'.format(target))
         elif label:
             info('Stored new text labeled "{}"'.format(label))
         else:
             info('Stored new text')
         mkdir(cellarpath.parent, parents=True, exist_ok=True)
         with cellarpath.open('w') as f:
             f.write(text)
         make_nonwritable(cellarpath)
     with cd(self.path):
         relink(os.path.relpath(str(cellarpath)), target)
     self.files[target] = cellarpath
Example #3
0
File: Context.py Project: azag0/caf
 def store_link_file(self, source, target=None):
     try:
         text = source.getvalue()
     except AttributeError:
         pass
     else:
         assert target
         self.store_link_text(text, target)
         return
     if not target:
         target = source
     if Path(source).is_dir():
         (self.path/target).mkdir()
         return
     filehash = get_file_hash(Path(source))
     cellarpath = self.ctx.cellar/str_to_path(filehash)
     if not cellarpath.is_file():
         info('Stored new file "{}"'.format(source))
         mkdir(cellarpath.parent, parents=True, exist_ok=True)
         shutil.copy(str(source), str(cellarpath))
         make_nonwritable(cellarpath)
     with cd(self.path):
         relink(os.path.relpath(str(cellarpath)), target)
     self.files[str(target)] = cellarpath