def add_file_from_string(self, filename, list_strings, commit_msg='', user=None): """ Add a ``filename`` to the repo using the list of strings to create the file. A commit will be written to the repo is ``commit_msg`` is not empty. """ fname = os.path.join(storage_dir, self.repo_path, filename) f = open(fname, 'w') f.writelines(list_strings) f.close() repo = DVCSRepo(backend, os.path.join(storage_dir, self.repo_path), dvcs_executable=revisioning_executable) # Save the location for next time globals()['revisioning_executable'] = repo.executable # Only add this file try: repo.add([fname]) except DVCSError as e: # Happens if a file with the same name already exists in the repo if e.value == 'Could not add one or more files to repository.': pass else: raise if commit_msg: repo.commit(commit_msg, user=user)
def get_hash(self): """ Returns the current repo hash for this fileset """ repo = DVCSRepo(backend, os.path.join(storage_dir, self.repo_path), do_init=False, dvcs_executable=revisioning_executable) return repo.get_revision_info()[0:60]
def checkout_revision(self, hash_id): """ Set the repo state to the revision given by ``hash_id`` Equivalent, for e.g., to ``hg checkout 28ed0c6faa19`` for that hash_id. """ repo = DVCSRepo(backend, os.path.join(storage_dir, self.repo_path), do_init=False, dvcs_executable=revisioning_executable) hash_str = repo.check_out(hash_id) if hash_str==hash_id: return repo else: return None
def checkout_revision(self, hash_id): """ Set the repo state to the revision given by ``hash_id`` Equivalent, for e.g., to ``hg checkout 28ed0c6faa19`` for that hash_id. """ repo = DVCSRepo(backend, os.path.join(storage_dir, self.repo_path), do_init=False, dvcs_executable=revisioning_executable) hash_str = repo.check_out(hash_id) if hash_str == hash_id: return repo else: return None
def get_repo(self): """ Returns the DVCS repo object """ return DVCSRepo(backend, os.path.join(storage_dir, self.repo_path), dvcs_executable=revisioning_executable)
def add_file(self, pattern, commit_msg='', user=None, repo=None): """ Add a single file, or a file ``pattern``, to the repo. A commit will be written to the repo if ``commit_msg`` is not empty. """ if repo is None: repo = DVCSRepo(backend, os.path.join(storage_dir, self.repo_path), do_init=False, dvcs_executable=revisioning_executable) try: repo.add([pattern]) except DVCSError as e: logger.error('DVCS error: %s' % e.original_message) if commit_msg: repo.commit(commit_msg, user=user)
def create_empty(self): """ Create an empty repo (``init``) and returns it. """ repo = DVCSRepo(backend, os.path.join(storage_dir, self.repo_path), do_init=True, dvcs_executable=revisioning_executable) # Save the location for next time globals()['revisioning_executable'] = repo.executable return repo