def store(self, path, hash=None): if hash == None: hash = fast_heuristic_hash(path) destpath = graftjoin(self.root, path + '.' + hash) if not os.path.exists(os.path.dirname(destpath)): os.makedirs(os.path.dirname(destpath)) if os.path.exists(path) and not os.path.exists(destpath): try: shutil.copy2(path, destpath) except: pass return destpath
def store_checked_product(self, storage): for path in self.check_product_paths: if not (os.path.isfile(path) or os.path.islink(path)): continue storedpath, hash = storage.check_stored(path) if storedpath == None: storedpath = storage.store(path, hash) linkpath = graftjoin(self.root, "P", path) if not os.path.exists(os.path.dirname(linkpath)): os.makedirs(os.path.dirname(linkpath)) os.symlink(os.path.relpath(storedpath, os.path.dirname(linkpath)), linkpath) self.product_paths.add(path)
def store_resource(self, path, storage): storedpath, hash = storage.check_stored(path) if storedpath == None: # not stored storedpath = storage.store(path, hash) linkpath = graftjoin(self.root, "R", path) if not os.path.exists(os.path.dirname(linkpath)): os.makedirs(os.path.dirname(linkpath)) if not os.path.exists(linkpath): os.symlink(os.path.relpath(storedpath,os.path.dirname(linkpath)), linkpath) else: # In MacOS X, store_resource is called more than twice with # the same path due to the case insensitivity of file system pass self.resource_paths.add(path)
def check_stored(self, path): hash = fast_heuristic_hash(path) storedpath = graftjoin(self.root, path + '.' + hash) if os.path.exists(storedpath): return storedpath, hash else: return None, hash