def test_simple(self): outstream = BytesIO() errstream = BytesIO() # create a file for initial commit handle, fullpath = tempfile.mkstemp(dir=self.repo.path) filename = os.path.basename(fullpath) porcelain.add(repo=self.repo.path, paths=filename) porcelain.commit(repo=self.repo.path, message='test', author='test', committer='test') # Setup target repo target_path = tempfile.mkdtemp() porcelain.clone(self.repo.path, target=target_path, outstream=outstream) # create a second file to be pushed handle, fullpath = tempfile.mkstemp(dir=self.repo.path) filename = os.path.basename(fullpath) porcelain.add(repo=self.repo.path, paths=filename) porcelain.commit(repo=self.repo.path, message='test2', author='test2', committer='test2') # Pull changes into the cloned repo porcelain.pull(target_path, self.repo.path, 'refs/heads/master', outstream=outstream, errstream=errstream) # Check the target repo for pushed changes r = Repo(target_path) self.assertEqual(r['HEAD'].id, self.repo['HEAD'].id)
def fetch(self): """Load from the associated Git repository.""" os.makedirs(os.path.dirname(self.cached_repo), exist_ok=True) if not os.path.exists(self.cached_repo): self._log.warning("Index not found, caching %s in %s", self.repo, self.cached_repo) git.clone(self.remote_url, self.cached_repo, checkout=True) else: self._log.debug("Index is cached in %s", self.cached_repo) try: diff = self._are_local_and_remote_heads_different() except Exception as e: self._log.warning( "There was a problem with reading the cached index so cloning from " "scratch: %s: %s", type(e).__name__, e) shutil.rmtree(self.cached_repo) self.fetch() return if diff: self._log.info("Cached index is not up to date, pulling %s", self.repo) git.pull(self.cached_repo, self.remote_url) with open(os.path.join(self.cached_repo, self.INDEX_FILE), encoding="utf-8") as _in: self.contents = json.load(_in)
def test_simple(self): outstream = BytesIO() errstream = BytesIO() # create a file for initial commit handle, fullpath = tempfile.mkstemp(dir=self.repo.path) filename = os.path.basename(fullpath) porcelain.add(repo=self.repo.path, paths=filename) porcelain.commit(repo=self.repo.path, message=b'test', author=b'test', committer=b'test') # Setup target repo target_path = tempfile.mkdtemp() porcelain.clone(self.repo.path, target=target_path, errstream=errstream) # create a second file to be pushed handle, fullpath = tempfile.mkstemp(dir=self.repo.path) filename = os.path.basename(fullpath) porcelain.add(repo=self.repo.path, paths=filename) porcelain.commit(repo=self.repo.path, message=b'test2', author=b'test2', committer=b'test2') # Pull changes into the cloned repo porcelain.pull(target_path, self.repo.path, b'refs/heads/master', outstream=outstream, errstream=errstream) # Check the target repo for pushed changes r = Repo(target_path) self.assertEqual(r[b'HEAD'].id, self.repo[b'HEAD'].id)
def test_simple(self): outstream = BytesIO() errstream = BytesIO() # create a file for initial commit handle, fullpath = tempfile.mkstemp(dir=self.repo.path) os.close(handle) filename = os.path.basename(fullpath) porcelain.add(repo=self.repo.path, paths=filename) porcelain.commit(repo=self.repo.path, message=b'test', author=b'test', committer=b'test') # Setup target repo target_path = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, target_path) target_repo = porcelain.clone(self.repo.path, target=target_path, errstream=errstream) target_repo.close() # create a second file to be pushed handle, fullpath = tempfile.mkstemp(dir=self.repo.path) os.close(handle) filename = os.path.basename(fullpath) porcelain.add(repo=self.repo.path, paths=filename) porcelain.commit(repo=self.repo.path, message=b'test2', author=b'test2', committer=b'test2') # Pull changes into the cloned repo porcelain.pull(target_path, self.repo.path, b'refs/heads/master', outstream=outstream, errstream=errstream) # Check the target repo for pushed changes with closing(Repo(target_path)) as r: self.assertEqual(r[b'HEAD'].id, self.repo[b'HEAD'].id)
def update_w3d(branch="master"): target_ref = 'refs/heads/{}'.format(branch).encode() w3d_repo = dulwich.repo.Repo(W3D_PATH) porcelain.reset(w3d_repo, "hard") porcelain.pull(W3D_PATH, REMOTE_PATH, target_ref) w3d_repo.refs.set_symbolic_ref('HEAD'.encode(), target_ref) porcelain.reset(w3d_repo, "hard")
def main(): root_dir = os.getcwd() repo_name = "acconeer-python-exploration" repo_dir = os.path.join(root_dir, repo_name) repo_addr = "https://github.com/acconeer/acconeer-python-exploration.git" python_dir = os.path.abspath(glob("tools\\python-3.7.*")[0]) python = os.path.abspath(os.path.join(python_dir, "python.exe")) # Check that pip is installed check_call([python, "-m", "pip", "--version"]) pip_install = [python, "-m", "pip", "install", "--no-warn-script-location"] # Install and import dulwich if importlib.util.find_spec("dulwich") is None: check_call(pip_install + ["urllib3", "certifi"]) check_call(pip_install + ["dulwich", "--global-option=--pure"]) from dulwich import porcelain # Clone/clean/update repo if os.path.isdir(repo_dir): os.chdir(repo_dir) porcelain.pull(".", repo_addr) else: os.chdir(root_dir) porcelain.clone(repo_addr, target=repo_dir) # Install requirements and acconeer_utils os.chdir(repo_dir) check_call(pip_install + ["-r", "requirements.txt"]) check_call(pip_install + ["."])
def _dulwich_pull(self, remote_location, refs_path, errstream=sys.stderr): """ Pull from remote via dulwich.porcelain :param repo: Path to repository :param remote_location: Location of the remote :param refs_path: relative path to the fetched refs """ pull(self.config['top_dir'], remote_location, refs_path)
def fetch_source(): if os.path.isdir('/tmp/source/.git'): print('pulling') porcelain.pull('/tmp/source', os.environ['SOURCE_GIT_URL'], 'refs/heads/master') else: print('cloning') porcelain.clone(os.environ['SOURCE_GIT_URL'], '/tmp/source') print('updated')
def run(self, args): parser = optparse.OptionParser() options, args = parser.parse_args(args) try: from_location = args[0] except IndexError: from_location = None porcelain.pull('.', from_location)
def update_local(self): if self.isaclone == 1: try: p.pull(self.repo, self.cloned_from) except: print "Error" else: print "Can not update"
def update_local(self): if self.isaclone == 1 or self.isaclone == 0: try: p.pull(self.repo_path, self.cloned_from) except Exception as e: print e else: print "Can not update"
def pull_botleague(): src = 'https://github.com/botleague/botleague' dst = constants.BOTLEAGUE_REPO_ROOT if not os.path.exists(constants.BOTLEAGUE_REPO_ROOT): porcelain.clone(src, dst) porcelain.pull( dst, remote_location=src, refspecs=b'refs/heads/master', )
def update_rules(r_path, l_path): try: f = open(os.devnull, 'wb') if (os.path.isdir(l_path) and validators.url(r_path)): porcelain.pull(l_path, r_path, b'refs/heads/master', errstream=f) return True else: return False except: sys_log(str(sys.exc_info()[1]), LOG_ERR)
def test_no_refspec(self): outstream = BytesIO() errstream = BytesIO() # Pull changes into the cloned repo porcelain.pull(self.target_path, self.repo.path, outstream=outstream, errstream=errstream) # Check the target repo for pushed changes with closing(Repo(self.target_path)) as r: self.assertEqual(r[b"HEAD"].id, self.repo[b"HEAD"].id)
def test_no_refspec(self): outstream = BytesIO() errstream = BytesIO() # Pull changes into the cloned repo porcelain.pull(self.target_path, self.repo.path, outstream=outstream, errstream=errstream) # Check the target repo for pushed changes with Repo(self.target_path) as r: self.assertEqual(r[b'HEAD'].id, self.repo[b'HEAD'].id)
def test_simple(self): outstream = BytesIO() errstream = BytesIO() # Pull changes into the cloned repo porcelain.pull(self.target_path, self.repo.path, b'refs/heads/master', outstream=outstream, errstream=errstream) # Check the target repo for pushed changes with Repo(self.target_path) as r: self.assertEqual(r[b'HEAD'].id, self.repo[b'HEAD'].id)
def check_for_updates(): if not os.path.exists('lib/code/'): print(f"{colored('Please install the minigame first', 'red')}") start_screen(first='Install') print(f"If there's any error that prevents program from starting, please tell {colored('Razbi', 'magenta')} about it. " f"Those are usually solved by deleting {colored('lib/db.sqlite', 'green')} or by asking {colored('Razbi', 'magenta')} for an updated .exe") input("Press enter to continue... [this is just a warning]: ") porcelain.pull("lib/code/") print(f"{colored('Program Updated [if there was any update available, the following text should let you figure that out, no, really, I have no easy way of figuring it out]', 'green')}") start_screen()
def handle_pull(): porcelain.pull(_repo, remote_location=config.github + ".git") for name in list(sys.modules.keys()): if name not in DONT_RELOAD: try: fh, path, details = imp.find_module(name) except: path = None if path and os.path.dirname(path) == os.getcwd(): imp.load_module(name, fh, path, details)
def pull(self, workspace, username=None, password=None, **kw): outstream = BytesIO() errstream = BytesIO() # XXX origin may be undefined target = self.get_remote(workspace, username=username, password=password) # XXX assuming repo is clean try: porcelain.pull(workspace.working_dir, target.encode(), outstream=outstream, errstream=errstream) except NotGitRepository as e: errstream.write(b'Not a Git repository ' + target.encode()) return outstream.getvalue().decode(), errstream.getvalue().decode()
def test_simple(self): outstream = BytesIO() errstream = BytesIO() # Pull changes into the cloned repo porcelain.pull(self.target_path, self.repo.path, b'refs/heads/master', outstream=outstream, errstream=errstream) # Check the target repo for pushed changes with closing(Repo(self.target_path)) as r: self.assertEqual(r[b'HEAD'].id, self.repo[b'HEAD'].id)
def git_pull(path, local_path="/tmp/giggity.git"): try: porcelain.pull(local_path, path) return local_path except dulwich.errors.NotGitRepository: t = tempfile.mkdtemp(prefix=local_path) repo = porcelain.clone(path, bare=True, target=t, checkout=False) try: os.rename(t, local_path) return local_path except OSError: # Guess there may have been a race. All we know # is the one we just created should work. return t
def update(self, repo_name): """ Updates the specified repository. If the repository is a git repository, this will pull the latest changes from origin. If the repository is a local directory, it is a no-op. """ repo = self.find(repo_name) if repo.type is 'git': repo_path = self.directory.joinpath(repo.name) with open(os.devnull, 'wb') as f: porcelain.pull(str(repo_path), remote_location=repo.location, outstream=f, errstream=f)
def update(): try: porcelain.pull(LOCAL_REPO, REMOTE_REPO) print('\nOPERAÇÃO REALIZADA COM SUCESSO...1') except: pass try: os.remove(HEADS) porcelain.pull(LOCAL_REPO, REMOTE_REPO) print('\nOPERAÇÃO REALIZADA COM SUCESSO...2') except: print('Deu erro') pass return True
def _git_pull(self): try: if self.git_repo: with Repo(self.git_repo) as repo: config = repo.get_config() remote_url = config.get(("remote".encode(), "origin".encode()), "url".encode()).decode() client.get_ssh_vendor = ParamikoSSHVendor try: porcelain.pull(repo, remote_url, password=self.settings['ssh_password']) except ssh_exception.SSHException as e: self.q.put([Action.add_error, _("Failed to pull from git: {}").format(str(e))]) return except FileLocked: print("File locked when trying to pull, giving up on this pull")
def fetch_index(self): os.makedirs(os.path.dirname(self.cached_repo), exist_ok=True) if not os.path.exists(self.cached_repo): self._log.warning("Index not found, caching %s in %s", self.repo, self.cached_repo) git.clone(self.remote_url, self.cached_repo, checkout=True) else: self._log.info("Index is cached") if self._are_local_and_remote_heads_different(): self._log.info("Cached index is not up to date, pulling %s", self.repo) git.pull(self.cached_repo, self.remote_url) with open(os.path.join(self.cached_repo, self.INDEX_FILE), encoding="utf-8") as _in: self.contents = json.load(_in)
def __clone_repo(self, repo_url, destination): """ This is to replicate the functionality of cloning/pulling a repo """ try: with open('/dev/null', 'wb') as devnull: porcelain.pull(destination, repo_url, outstream=devnull, errstream=devnull) repo = porcelain.open_repo(destination) except dulwich.errors.NotGitRepository: with open('/dev/null', 'wb') as devnull: repo = porcelain.clone(repo_url, destination, outstream=devnull, errstream=devnull) remote_refs = porcelain.fetch(repo, repo_url) ref = f'refs/heads/{self.branch}'.encode() try: repo[ref] = remote_refs[ref] except KeyError: ref = b'refs/heads/master' msgs = [ f'\nBranch {self.branch} does not exist at {repo_url}!', 'Using "master" branch for plugin, this may not work ' 'with your RELEASE' ] for msg in msgs: iocage_lib.ioc_common.logit({ 'level': 'INFO', 'message': msg }, _callback=self.callback) repo[ref] = remote_refs[ref] tree = repo[ref].tree # Let git reflect reality repo.reset_index(tree) repo.refs.set_symbolic_ref(b'HEAD', ref)
def clone_repository_and_import(self, repo_url): repo_url = repo_url.strip() try: repo_local_path = self.get_repo_local_path(repo_url) porcelain.pull(str(repo_local_path), repo_url) except ValueError: return self.notifier.error( "URL incorrect", f"URL could not be parsed \"{repo_url}\"") except NotGitRepository: try: self.clone_repository(repo_url, repo_local_path) except (GitProtocolError, NotGitRepository): return self.notifier.error( "repository not found", f"git repository not found at URL {repo_url}") AnkiJsonImporter.import_deck_from_path(self.collection, repo_local_path)
def __clone_repo(self, repo_url, destination): """ This is to replicate the functionality of cloning/pulling a repo """ try: with open('/dev/null', 'wb') as devnull: porcelain.pull(destination, repo_url, outstream=devnull, errstream=devnull) repo = porcelain.open_repo(destination) except dulwich.errors.NotGitRepository: with open('/dev/null', 'wb') as devnull: repo = porcelain.clone( repo_url, destination, outstream=devnull, errstream=devnull ) remote_refs = porcelain.fetch(repo, repo_url) ref = f'refs/heads/{self.branch}'.encode() try: repo[ref] = remote_refs[ref] except KeyError: ref = b'refs/heads/master' msgs = [ f'\nBranch {self.branch} does not exist at {repo_url}!', 'Using "master" branch for plugin, this may not work ' 'with your RELEASE' ] for msg in msgs: iocage_lib.ioc_common.logit( { 'level': 'INFO', 'message': msg }, _callback=self.callback) repo[ref] = remote_refs[ref] tree = repo[ref].tree # Let git reflect reality repo.reset_index(tree) repo.refs.set_symbolic_ref(b'HEAD', ref)
def _update_app(self, _): """Perform app update.""" cannot_modify = self.cannot_modify_app() if cannot_modify: self.install_info.value = """<i class="fa fa-times" style="color:red;font-size:4em;" > </i>Can not update the repository: {}""".format(cannot_modify) sleep(3) self.install_info.value = '' return self.install_info.value = """<i class="fa fa-spinner fa-pulse" style="color:#337ab7;font-size:4em;" ></i> <font size="1"><blink>Updating the app...</blink></font>""" fetch(repo=self.repo, remote_location=self._git_url) pull(repo=self.repo, remote_location=self._git_url, refspecs=self.version.selected.label) self.install_info.value = """<i class="fa fa-check" style="color:#337ab7;font-size:4em;" ></i> <font size="1">Success</font>""" self._refresh_update_button() sleep(1) self.install_info.value = ''
def update_dulwich(): try: import dulwich.repo from dulwich import porcelain except ImportError: install_dulwich() return try: dulwich_repo = dulwich.repo.Repo(os.path.join(INSTALL_PATH, "dulwich")) except dulwich.errors.NotGitRepository: try: shutil.rmtree(os.path.join(INSTALL_PATH, "dulwich")) except FileNotFoundError: pass # Directory already gone dulwich_repo = porcelain.clone("https://github.com/jelmer/dulwich.git", os.path.join(INSTALL_PATH, "dulwich")) porcelain.reset(dulwich_repo, "hard") porcelain.pull(dulwich_repo, remote_location="https://github.com/jelmer/dulwich.git") install_dulwich()
def update(repo_url, logger=None): if logger: logger.info("Updating docs for: %s", repo_url) else: print("Updating docs for: %s" % repo_url) try: shutil.rmtree(package_folder_name) except: pass repo = porcelain.clone(package_git_url, package_folder_name) refspecs = b"HEAD:refs/heads/%s" %package_git_branch porcelain.pull(repo, package_git_url, refspecs = refspecs) repo_url = repo_url.split("\n")[0] repo_name = repo_url.split('/')[-1] readme_md, readme_name = loadReadme(repo_url) readme_md, readme_title = addTitleToReadme(readme_md, repo_url) readme_md = addEditLink(readme_md, readme_name, repo_url) updateMenu(readme_md, repo_name, repo) updateReadmePage(readme_md, repo_name, repo) updateLandingPage(readme_title, repo) staged = porcelain.status(repo).staged if (len(staged['add']) == 0) and (len(staged['modify']) == 0): if logger: logger.info("No changes to commit") else: print("No changes to commit") else: if logger: logger.info("Commiting changes for %s", repo_name) else: print("Commiting changes for %s" % repo_name) porcelain.commit(repo, b"Updated docs for %s" % repo_name) porcelain.push(repo, package_git_url, refspecs = refspecs) try: shutil.rmtree(package_folder_name) except Exception, err: if logger: logger.exception(err) else: print(err)
def __update_pull_plugin_index__(self): """Pull the latest index to be sure we're up to date""" if self.server == "download.freebsd.org": git_server = "https://github.com/freenas/iocage-ix-plugins.git" else: git_server = self.server git_working_dir = f"{self.iocroot}/.plugin_index" try: with open("/dev/null", "wb") as devnull: porcelain.pull(git_working_dir, git_server, outstream=devnull, errstream=devnull) except Exception as err: iocage_lib.ioc_common.logit( { "level": "EXCEPTION", "message": err }, _callback=self.callback)
def run_nextflow(run, params, rundir, gitwfdir, profiles, nf_version=False): """Fairly generalized code for kantele celery task to run a WF in NXF""" print('Starting nextflow workflow {}'.format(run['nxf_wf_fn'])) outdir = os.path.join(rundir, 'output') try: clone(run['repo'], gitwfdir, checkout=run['wf_commit']) except FileExistsError: pull(gitwfdir, run['repo']) reset(gitwfdir, 'hard', run['wf_commit']) # FIXME dulwich does not seem to checkout anything, use this until it does subprocess.run(['git', 'checkout', run['wf_commit']], check=True, cwd=gitwfdir) print('Checked out repo {} at commit {}'.format(run['repo'], run['wf_commit'])) # There will be files inside data dir of WF repo so we must be in # that dir for WF to find them cmd = ['nextflow', 'run', run['nxf_wf_fn'], *params, '--outdir', outdir, '-profile', profiles, '-with-trace', '-resume'] print(cmd) env = os.environ if nf_version: env['NXF_VER'] = nf_version log_analysis(run['analysis_id'], 'Running command {}, nextflow version {}'.format(' '.join(cmd), env.get('NXF_VER', 'default'))) subprocess.run(cmd, check=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE, cwd=gitwfdir, env=env) return rundir
def pull(self, remote_location, branch): import logging logging.warning("Pulling from %s:%s" % (remote_location, branch)) git.pull(self, remote_location, branch)
def git_pull(repo_path: str) -> None: """ Does a git pull on a repository """ porcelain.pull(repo_path)
def download_collection(self, id, register_name): """Download a collection given its ID. For remote git repositories, we will clone the repository first (or pull if the repo is already cloned before) and copy the collection to collections dir. :param id: The ID of the collection. :type id: str :param register_name: The register name of the collection (the section name of the collection) :type register_name: unicode """ # Clone or pull the repositories first local_repo_dir = os.path.join( QgsApplication.qgisSettingsDirPath(), 'resource_sharing', 'repositories', self.git_host, self.git_owner, self.git_repository ) if not os.path.exists(os.path.join(local_repo_dir, '.git')): os.makedirs(local_repo_dir) try: repo = porcelain.clone( self.url, local_repo_dir, errstream=writeOut ) except Exception as e: # Try to clone with https if it's ssh url git_parsed = parse(self.url) if self.url == git_parsed.url2ssh: try: repo = porcelain.clone( git_parsed.url2https, local_repo_dir, errstream=writeOut) except Exception as e: error_message = 'Error: %s' % str(e) LOGGER.exception(traceback.format_exc()) return False, error_message else: error_message = 'Error: %s' % str(e) LOGGER.exception(traceback.format_exc()) return False, error_message if not repo: error_message = ('Error: Cloning the repository of the ' 'collection failed.') return False, error_message else: try: porcelain.pull( local_repo_dir, self.url, b'refs/heads/master', errstream=writeOut ) except Exception as e: # Try to pull with https if it's ssh url git_parsed = parse(self.url) if self.url == git_parsed.url2ssh: try: porcelain.pull( local_repo_dir, git_parsed.url2https, b'refs/heads/master', errstream=writeOut ) except Exception as e: error_message = 'Error: %s' % str(e) LOGGER.exception(traceback.format_exc()) return False, error_message else: error_message = 'Error: %s' % str(e) LOGGER.exception(traceback.format_exc()) return False, error_message # Copy the specific downloaded collection to collections dir src_dir = os.path.join(local_repo_dir, 'collections', register_name) if not os.path.exists(src_dir): error_message = ('Error: The collection does not exist in the ' 'repository.') return False, error_message dest_dir = local_collection_path(id) if os.path.exists(dest_dir): shutil.rmtree(dest_dir) shutil.copytree(src_dir, dest_dir) return True, None
def pull(self, remote_location, branch): git.pull(self, remote_location, branch)
def fetch_plugin_index(self, props, _list=False, list_header=False, list_long=False, accept_license=False, icon=False): if self.server == "download.freebsd.org": git_server = "https://github.com/freenas/iocage-ix-plugins.git" else: git_server = self.server git_working_dir = f"{self.iocroot}/.plugin_index" # list --plugins won't often be root. if os.geteuid() == 0: try: with open("/dev/null", "wb") as devnull: porcelain.clone(git_server, git_working_dir, outstream=devnull, errstream=devnull) except FileExistsError: try: with open("/dev/null", "wb") as devnull: porcelain.pull(git_working_dir, git_server, outstream=devnull, errstream=devnull) except Exception as err: iocage.lib.ioc_common.logit( { "level": "EXCEPTION", "message": err }, exit_on_error=self.exit_on_error, _callback=self.callback, silent=self.silent) with open(f"{self.iocroot}/.plugin_index/INDEX", "r") as plugins: plugins = json.load(plugins) _plugins = self.__fetch_sort_plugin__(plugins) if self.plugin is None and not _list: for p in _plugins: iocage.lib.ioc_common.logit( { "level": "INFO", "message": f"[{_plugins.index(p)}] {p}" }, _callback=self.callback, silent=self.silent) if _list: plugin_list = [] for p in _plugins: p = p.split("-", 1) name = p[0] desc, pkg = re.sub(r'[()]', '', p[1]).rsplit(" ", 1) license = plugins[pkg].get("license", "") icon_path = plugins[pkg].get("icon", None) p = [name, desc, pkg] if not list_header: p += [license] if icon: p += [icon_path] plugin_list.append(p) if not list_header: return plugin_list else: if list_long: table = texttable.Texttable(max_width=0) else: table = texttable.Texttable(max_width=80) list_header = ["NAME", "DESCRIPTION", "PKG"] if icon: list_header += ["ICON"] plugin_list.insert(0, list_header) table.add_rows(plugin_list) return table.draw() if self.plugin is None: self.plugin = input("\nType the number of the desired" " plugin\nPress [Enter] or type EXIT to" " quit: ") self.plugin = self.__fetch_validate_plugin__(self.plugin.lower(), _plugins) self.fetch_plugin(f"{self.iocroot}/.plugin_index/{self.plugin}.json", props, 0, accept_license)