def get_git_version(): g = git.Git(".") return g.describe(tags=True)
def setup_workspace(workspace): (workspace.workspace + "/templates").mkdir() git.Git(workspace.workspace).init() (workspace.workspace + "/templates/fake").mkdir() report_to_run = workspace.workspace + "/templates/fake/report.py" report_to_run.write_lines(DUMMY_REPORT.split("\n"))
def process_source(self, image, source): dest_archive = os.path.join(image.path, source['name'] + '-archive') if source.get('type') == 'url': self.logger.debug("Getting archive from %s", source['source']) try: r = requests.get(source['source'], timeout=self.conf.timeout) except requests_exc.Timeout: self.logger.exception( 'Request timed out while getting archive from %s', source['source']) image.status = STATUS_ERROR return if r.status_code == 200: with open(dest_archive, 'wb') as f: f.write(r.content) else: self.logger.error('Failed to download archive: status_code %s', r.status_code) image.status = STATUS_ERROR return elif source.get('type') == 'git': clone_dir = '{}-{}'.format(dest_archive, source['reference'].replace('/', '-')) if os.path.exists(clone_dir): self.logger.info("Clone dir %s exists. Removing it.", clone_dir) shutil.rmtree(clone_dir) try: self.logger.debug("Cloning from %s", source['source']) git.Git().clone(source['source'], clone_dir) git.Git(clone_dir).checkout(source['reference']) reference_sha = git.Git(clone_dir).rev_parse('HEAD') self.logger.debug("Git checkout by reference %s (%s)", source['reference'], reference_sha) except Exception as e: self.logger.error("Failed to get source from git", image.name) self.logger.error("Error: %s", e) # clean-up clone folder to retry shutil.rmtree(clone_dir) image.status = STATUS_ERROR return with tarfile.open(dest_archive, 'w') as tar: tar.add(clone_dir, arcname=os.path.basename(clone_dir)) elif source.get('type') == 'local': self.logger.debug("Getting local archive from %s", source['source']) if os.path.isdir(source['source']): with tarfile.open(dest_archive, 'w') as tar: tar.add(source['source'], arcname=os.path.basename(source['source'])) else: shutil.copyfile(source['source'], dest_archive) else: self.logger.error("Wrong source type '%s'", source.get('type')) image.status = STATUS_ERROR return # Set time on destination archive to epoch 0 os.utime(dest_archive, (0, 0)) return dest_archive
def GitHubDownLoad(githubLink: str): try: git.Git().clone(githubLink) except: print("Error")
def _clone_directory(self, url: str) -> None: """Clones the repo from `url` into `self._store_dir`.""" if not self._store_dir.exists(): self._store_dir.mkdir() git.Git(self._store_dir).clone(url)
# create out directory try: os.stat("./out") except: os.mkdir("./out") # import a/o update the EventsGallery if os.path.exists("./EventsGallery"): print("Pulling from EventsGallery...") repo = git.Repo("./EventsGallery") repo.remotes.origin.pull() else: print("Cloning EventsGallery...") git.Git(".").clone("https://github.com/projectpokemon/EventsGallery.git") # loop generations print("Creating data...") for gen in range(4, 7 + 1): # set root path root = "./EventsGallery/Released/Gen {}/Wondercards".format(gen) # initialize sheet sheet = {} sheet['gen'] = gen sheet['wondercards'] = [] # initialize data data = b''
# from parlai.core.logging_utils import logger # TODO: Uncomment before completion of #2044 try: import torch TORCH_AVAILABLE = True GPU_AVAILABLE = torch.cuda.device_count() > 0 except ImportError: TORCH_AVAILABLE = False GPU_AVAILABLE = False try: import git git_ = git.Git() GIT_AVAILABLE = True except ImportError: git_ = None GIT_AVAILABLE = False DEBUG = False # change this to true to print to stdout anyway def is_this_circleci(): """Return if we are currently running in CircleCI.""" return bool(os.environ.get('CIRCLECI')) def skipUnlessTorch(testfn, reason='pytorch is not installed'):
def git_squash_streaks(): """ git-squash-streaks Usage: See argparse """ import argparse try: import argcomplete except ImportError: argcomplete = None raise description, help_dict = _autoparse_desc(squash_streaks) parser = argparse.ArgumentParser(description=description) parser.add_argument(*('--timedelta', ), type=str, help=help_dict['timedelta']) parser.add_argument(*('--pattern', ), type=str, help=help_dict['pattern']) parser.add_argument(*('--inplace', ), action='store_true', help=help_dict['inplace']) parser.add_argument(*('--auto-rollback', ), action='store_true', dest='auto_rollback', help=help_dict['auto_rollback']) parser.add_argument('--authors', type=str, help=(help_dict['authors'] + ' Defaults to your git config user.name')) group = parser.add_mutually_exclusive_group() group.add_argument(*('-n', '--dry'), dest='dry', action='store_true', help=help_dict['dry']) group.add_argument(*('-f', '--force'), dest='dry', action='store_false', help='opposite of --dry') group = parser.add_mutually_exclusive_group() group.add_argument(*('-v', '--verbose'), dest='verbose', action='store_const', const=1, help='verbosity flag flag') group.add_argument(*('-q', '--quiet'), dest='verbose', action='store_const', const=0, help='suppress output') parser.set_defaults( inplace=False, auto_rollback=False, authors=None, pattern=None, timedelta='sameday', dry=True, verbose=True, ) if argcomplete: argcomplete.autocomplete(parser) args = parser.parse_args() # Postprocess args ns = args.__dict__.copy() try: ns['timedelta'] = float(ns['timedelta']) except ValueError: valid_timedelta_categories = ['sameday', 'alltime'] if ns['timedelta'] not in valid_timedelta_categories: raise ValueError('timedelta = {}'.format(ns['timedelta'])) if ns['authors'] is None: ns['authors'] = {git.Git().config('user.name')} # HACK: for me. todo user alias # SEE: .mailmap file to auto extract? # https://git-scm.com/docs/git-shortlog#_mapping_authors """ # .mailmap # Proper Name <*****@*****.**> Commit Name <*****@*****.**> Jon Crall <*****@*****.**> joncrall <*****@*****.**> Jon Crall <*****@*****.**> jon.crall <*****@*****.**> Jon Crall <*****@*****.**> Jon Crall <*****@*****.**> Jon Crall <*****@*****.**> joncrall <*****@*****.**> Jon Crall <*****@*****.**> joncrall <*****@*****.**> Jon Crall <*****@*****.**> Jon Crall <*****@*****.**> """ if {'joncrall', 'Jon Crall', 'jon.crall'}.intersection(ns['authors']): ns['authors'].update({'joncrall', 'Jon Crall'}) else: ns['authors'] = {a.strip() for a in ns['authors'].split(',')} print(ub.repr2(ns, nl=1)) squash_streaks(**ns) if ns['dry']: if ns['verbose']: print('Finished the dry run. Use -f to force')
def run(self): if NOGIT: self.stop = True return try: import git except: self.stop = True return self.progressbar_show.emit(True) basedir = FreeCAD.ConfigGet("UserAppData") moddir = basedir + os.sep + "Mod" self.info_label.emit( translate("AddonsInstaller", "Checking for new versions...")) upds = [] gitpython_warning = False for repo in self.repos: if repo[2] == 1: #installed self.info_label.emit( translate("AddonsInstaller", "Checking repo") + " " + repo[0] + "...") clonedir = moddir + os.sep + repo[0] if os.path.exists(clonedir): if not os.path.exists(clonedir + os.sep + '.git'): # Repair addon installed with raw download bare_repo = git.Repo.clone_from(repo[1], clonedir + os.sep + '.git', bare=True) try: with bare_repo.config_writer() as cw: cw.set('core', 'bare', False) except AttributeError: if not gitpython_warning: FreeCAD.Console.PrintWarning( translate( "AddonsInstaller", "Outdated GitPython detected, consider upgrading with pip.\n" )) gitpython_warning = True cw = bare_repo.config_writer() cw.set('core', 'bare', False) del cw repo = git.Repo(clonedir) repo.head.reset('--hard') gitrepo = git.Git(clonedir) gitrepo.fetch() if "git pull" in gitrepo.status(): self.mark.emit(repo[0]) upds.append(repo[0]) self.progressbar_show.emit(False) if upds: self.info_label.emit( str(len(upds)) + " " + translate("AddonsInstaller", "update(s) available") + ": " + ",".join(upds) + ". " + translate( "AddonsInstaller", "Press the update button again to update them all at once." )) else: self.info_label.emit( translate("AddonsInstaller", "Everything is up to date")) self.stop = True
def init(ctx, git_repository, path): """ @@ignore_check@@ """ try: if git_repository == '.': path = os.getcwd() elif not path: path = os.path.join( os.getcwd(), git_repository.split('/')[-1].replace('.git', '')) ctx.working_dir = path if git_repository != '.': git.Git().clone(git_repository, path) click.secho('Git repository cloned to: "{}"'.format(path), fg='green') if not os.path.exists(os.path.join(ctx.working_dir, '.stylist')): prefix = click.prompt(click.style('Prefix name for environments', fg='blue'), default='') try: os.makedirs(ctx.config_dir) except: pass with open(ctx.config_file, 'w+') as f: yaml.dump( { 'stylist': { 'provider': { 'type': 'aws', 'prefix': str(prefix) }, 'stages': ['prod', 'uat', 'staging'] } }, f) def deal_with_gitignore(): gitignore_path = os.path.join(path, '.gitignore') mode = 'a' if os.path.isfile(gitignore_path) else 'w' with open(gitignore_path, mode) as f: f.write(GIT_IGNORE) for to_add in ('.gitignore', '.stylist'): call(['git', 'add', to_add]) deal_with_gitignore() from stylist.commands.cmd_profile import select click.get_current_context().invoke(select, name='local') except Exception as e: logger.error( 'Failed to create project - you may need clean it up manually. \n{}' .format(e)) sys.exit(1)
import toml from invoke import task ROOT_DIR = Path(__file__).parent TOX_DIR = ROOT_DIR.joinpath(".tox") COVERAGE_DIR = ROOT_DIR.joinpath("htmlcov") COVERAGE_REPORT = COVERAGE_DIR.joinpath("index.html") # SPHINX_DIR = ROOT_DIR.joinpath(".sphinx") # SPHINX_BUILD_DIR = SPHINX_DIR.joinpath(".build") # SPHINX_INDEX = SPHINX_BUILD_DIR.joinpath("index.html") # DOCUSAURUS_DIR = ROOT_DIR.joinpath(".website") # NOTEBOOKS_DIR = ROOT_DIR.joinpath(".notebooks") SCRIPTS_DIR = ROOT_DIR.joinpath("scripts") _GIT = git.Git() _GIT_LOCAL_REPO = git.Repo() # todo: make this more secure. Is this recommended?? # This keeps env variable exposed _GITHUB = github.Github( login_or_token=os.environ.get("PK_PYGITHUB_TOKEN_PK", None)) # we will not do authentication as this is public repo # _GITHUB = github.Github() _GH_REMOTE_REPO = _GITHUB.get_repo("SpikingNeurons/toolcraft") def _find( pattern: str, path: pathlib.Path, recursive: bool, ) -> t.List[pathlib.Path]:
def downloadRepositoryWindows(url): # Fetching the arguement from the command line, which contains the real name for the repo # Snippet to find the filename from the URL [url_first_part, mname] = url.rsplit('/', 1) mname = mname.replace('.git', '') # To create new directory used in place of mkdir for keeping the projects projectPathWindows = dir_path + '\sonarScanner\\bin\project' # Create the project here if it doesn't exist if not os.path.exists(projectPathWindows): os.makedirs(projectPathWindows) # Cloning the repo into the path1 variable git.Git(projectPathWindows + "\\").clone(url) print("\nThe repo has been cloned in our system ............... \n ") # Path of the properties file propertiesFilePath = dir_path + '\sonarScanner\conf\sonar-scanner.properties' # For comparing purposes data1 = open(propertiesFilePath, 'r') # Reading the properties file with open(propertiesFilePath, 'r') as file: data = file.readlines() # Reading the properties File and deleting all the contents in them print("\nDeleting Old properties ................ \n") f = open(propertiesFilePath, 'r+') f.truncate(0) data = f.readlines() # Appending the properties in the file one by one data.append("sonar.sourceEncoding=UTF-8") data.append("\n") data.append("\n") data.append("export SONAR_SCANNER_OPTS=-Xms512m\ -Xmx2048m") data.append("\n") data.append("\n") data.append("sonar.projectKey=" + mname) data.append("\n") data.append("\n") data.append("sonar.projectName=" + mname) data.append("\n") data.append("\n") data.append("sonar.projectVersion=1.0") data.append("\n") data.append("\n") data.append("sonar.scm.disabled=true") data.append("\n") data.append("\n") #data.append("sonar.nodejs.executable=/usr/local/n/versions/node/11.6.0") #converting to double slash to write to file doubleSlashPathWindows = dir_path.replace('\\', '\\\\') data.append("sonar.sources=" + doubleSlashPathWindows + "\\\\sonarScanner\\\\bin\\\\project\\\\" + mname) data.append("\n") data.append("\n") data.append("sonar.java.binaries=" + doubleSlashPathWindows + "\\\\sonarScanner\\\\bin\\\\project\\\\" + mname) data.append("\n") # and write everything back with open(propertiesFilePath, 'w') as file: file.writelines(data) # Running the command for scanning the files print("\n Running sonar-scanner.bat file. \n Scanning of " + mname + " repo started ................. \n") p = Popen(dir_path + "\sonarScanner\\bin\sonar-scanner.bat") stdout, stderr = p.communicate() # Remaning the project name with current Date and Time tempTime = datetime.datetime.now() tempTime = tempTime.strftime("%Y-%m-%d--%H-%M") os.rename(projectPathWindows + "\\" + mname, projectPathWindows + "\\" + mname + tempTime)
def downloadRepositoryMac(url): # Snippet to find the filename from the URL [url_first_part, mname] = url.rsplit('/', 1) mname = mname.replace('.git', '') subprocess.call("mkdir -p sonarScanner/bin/project", shell=True) # Path where you want to download the project path2 = dir_path + '/sonarScanner/bin/project/' print("\nDownloading Started ............ \n") # Cloning the repo into the path1 variable git.Git(path2).clone(url) print("\nThe repo has been cloned in our system .................... \n") # Path of the properties file propertiesFilePath = dir_path + '/sonarScanner/conf/sonar-scanner.properties' # Reading the properties File and deleting all the contents in them print("\nDeleting Old properties ................ \n") f = open(propertiesFilePath, 'r+') f.truncate(0) data = f.readlines() # Appending the properties in the file one by one data.append("sonar.sourceEncoding=UTF-8") data.append("\n") data.append("\n") data.append("export SONAR_SCANNER_OPTS=-Xms512m\ -Xmx2048m") data.append("\n") data.append("\n") data.append("sonar.projectKey=" + mname) data.append("\n") data.append("\n") data.append("sonar.projectName=" + mname) data.append("\n") data.append("\n") data.append("sonar.projectVersion=1.0") data.append("\n") data.append("\n") data.append("sonar.scm.disabled=true") data.append("\n") data.append("\n") #data.append("sonar.nodejs.executable=/usr/local/n/versions/node/11.6.0") data.append("sonar.sources=" + dir_path + "/sonarScanner/bin/project/" + mname) data.append("\n") data.append("\n") data.append("sonar.java.binaries=" + dir_path + "/sonarScanner/bin/project/" + mname) # and write everything back with open(propertiesFilePath, 'w') as file: file.writelines(data) # Running the command for scanning the files # Changing the mod for sonarScanner in Unix print("\nChanging the mode of sonarScanner directory ............. \n") subprocess.call("chmod -R 777 sonarScanner", shell=True) bashCommand = './sonarScanner/bin/sonar-scanner' print("\nRunning sonarScanner.sh file.\nScanning of " + mname + " repo started ................. \n") # Running the sonarScanner in Unix process = subprocess.call(bashCommand, shell=True) tempTime = str(datetime.datetime.now()) os.rename(path2 + mname, path2 + mname + tempTime)
def get_date_git(dir_p, commit_id): repo = git.Repo(dir_p) g = git.Git(dir_p) loginfo = g.log() res = get_date_log_info(loginfo.encode('utf8'), commit_id) return res
def clone_repo(namespace, repo_url): clone_dir = f'{clone}/{namespace}' os.makedirs(clone_dir, exist_ok=True) git.Git(clone_dir).clone(repo_url)
def run(self): "installs or updates the selected addon" git = None try: import git except: self.info_label.emit("GitPython not found.") FreeCAD.Console.PrintWarning( translate( "AddonsInstaller", "GitPython not found. Using standard download instead.\n")) try: import zipfile except: self.info_label.emit("no zip support.") FreeCAD.Console.PrintError( translate( "AddonsInstaller", "Your version of python doesn't appear to support ZIP files. Unable to proceed.\n" )) return try: import StringIO as io except ImportError: # StringIO is not available with python3 import io if not isinstance(self.idx, list): self.idx = [self.idx] for idx in self.idx: if idx < 0: return if not self.repos: return if NOGIT: git = None basedir = FreeCAD.ConfigGet("UserAppData") moddir = basedir + os.sep + "Mod" if not os.path.exists(moddir): os.makedirs(moddir) clonedir = moddir + os.sep + self.repos[idx][0] self.progressbar_show.emit(True) if os.path.exists(clonedir): self.info_label.emit("Updating module...") if git: if not os.path.exists(clonedir + os.sep + '.git'): # Repair addon installed with raw download bare_repo = git.Repo.clone_from(self.repos[idx][1], clonedir + os.sep + '.git', bare=True) try: with bare_repo.config_writer() as cw: cw.set('core', 'bare', False) except AttributeError: FreeCAD.Console.PrintWarning( translate( "AddonsInstaller", "Outdated GitPython detected, consider upgrading with pip.\n" )) cw = bare_repo.config_writer() cw.set('core', 'bare', False) del cw repo = git.Repo(clonedir) repo.head.reset('--hard') repo = git.Git(clonedir) answer = repo.pull() # Update the submodules for this repository repo_sms = git.Repo(clonedir) for submodule in repo_sms.submodules: submodule.update(init=True, recursive=True) else: answer = self.download(self.repos[idx][1], clonedir) else: self.info_label.emit("Checking module dependencies...") depsok, answer = self.checkDependencies(self.repos[idx][1]) if depsok: if git: self.info_label.emit("Cloning module...") repo = git.Repo.clone_from(self.repos[idx][1], clonedir, branch='master') # Make sure to clone all the submodules as well if repo.submodules: repo.submodule_update(recursive=True) else: self.info_label.emit("Downloading module...") self.download(self.repos[idx][1], clonedir) answer = translate( "AddonsInstaller", "Workbench successfully installed. Please restart FreeCAD to apply the changes." ) # symlink any macro contained in the module to the macros folder macrodir = FreeCAD.ParamGet( "User parameter:BaseApp/Preferences/Macro").GetString( "MacroPath", os.path.join(FreeCAD.ConfigGet("UserAppData"), "Macro")) if not os.path.exists(macrodir): os.makedirs(macrodir) for f in os.listdir(clonedir): if f.lower().endswith(".fcmacro"): symlink(clonedir + os.sep + f, macrodir + os.sep + f) FreeCAD.ParamGet('User parameter:Plugins/' + self.repos[idx][0]).SetString( "destination", clonedir) answer += translate( "AddonsInstaller", "A macro has been installed and is available the Macros menu" ) + ": <b>" answer += f + "</b>" self.info_label.emit(answer) self.progressbar_show.emit(False) self.stop = True
def h(repo): print "\t\th)" g = git.Git(getPath(repo)) #gitP = subprocess.Popen(('git log --pretty=format:"" --diff-filter=A --summary'), shell=True, stdout=PIPE) #diffP = subprocess.Popen(('grep create'), shell=True, stdin=gitP.stdout, stdout=PIPE) #c = subprocess.check_output('wc -l', shell=True, stdin=diffP.stdout) #c = c.strip('\n') #gitP.wait() #diffP.wait() logInfo = g.log('--pretty=format:""', '--diff-filter=A', '--summary', '--since="1 year ago"') logToList = logInfo.split('\n') #for log in logToList: #print log #print "size:", len(logToList) for i, val in enumerate(logToList): logToList[i] = str(val).strip('"') #print logToList createNum = 0 for log in logToList: if "mode" in log: createNum += 1 # print the lines that are obtained from the log query # print log #print "log size:", len(logToList) print "\t\t\tNumber Of Files Added:", createNum logInfo = g.log('--pretty=format:""', '--diff-filter=D', '--summary') logToList = logInfo.split('\n') for i, val in enumerate(logToList): logToList[i] = str(val).strip('"') deleteNum = 0 for log in logToList: if "delete" in log: deleteNum += 1 # print the lines that are obtained from the log query # print log #print "log size:", len(logToList) print "\t\t\tNumber Of Files Deleted:", deleteNum logInfo = g.log('--pretty=format:tformat', '--diff-filter=M') #print logInfo logToList = str(logInfo).split('\n') #for log in logToList: #print log modifyNum = len(logToList) # print the lines that are obtained from the log query # print log #print "log size:", len(logToList) print "\t\t\tNumber Of Files Modified:", modifyNum
def git_clone(clone_dir, repostiry): git.Git(clone_dir).clone(repostiry) print("Successfully clone the repository %s " % repostiry)
import glob import errno from requests.exceptions import ConnectionError with open('config.json', 'r') as f: config = json.load(f) if os.path.isdir(config['paths']['gitrepopath']): print("Project already cloned") # git.Git("App").pull("https://github.com/MinusculeTechnologiesLtd/mobilecode.git") repo = git.Repo(config['paths']['gitrepopath'] + '/mobilecode') o = repo.remotes.origin o.pull() else: os.mkdir(config['paths']['gitrepopath']) print("This is a Fresh Checkout...") # Repo.clone_from("https://github.com/MinusculeTechnologiesLtd/mobilecode.git", "App") git.Git(config['paths']['gitrepopath']).clone(config['paths']['giturl']) choice = sys.argv[1] print("You choosed : %s" % choice) tspath = config['paths'][choice]['tspath'] xmlpath = config['paths'][choice]['xmlpath'] jsonpath = config['paths'][choice]['jsonpath'] apkpath = config['paths'][choice]['apkpath'] shutil.copy2( xmlpath, config['paths']['gitrepopath'] + '/mobilecode/' + config['paths']['prod']['xmlpath']) shutil.copy2( tspath, config['paths']['gitrepopath'] + '/mobilecode/' + config['paths']['prod']['tspath']) shutil.copy2( jsonpath, config['paths']['gitrepopath'] + '/mobilecode/' +
import shutil import sys import tempfile import time from .backends import S3Backend from .backends import RackspaceBackend from .backends import GoogleBackend from dateutil import tz as dateutil_tz import boto import git import pytz attribute_regex = re.compile(r'^([^\s]*) .+ filter=(bigstore(?:-compress)?)$') g = git.Git('.') git_directory = g.rev_parse(git_dir=True) try: default_hash_function_name = g.config("bigstore.hash_function") except git.exc.GitCommandError: default_hash_function_name = 'sha1' hash_functions = { 'md5': hashlib.md5, 'sha1': hashlib.sha1, 'sha224': hashlib.sha224, 'sha256': hashlib.sha256, 'sha384': hashlib.sha384, 'sha512': hashlib.sha512 }
import csv # pip install GitPython import git import yaml git.Git(".").clone("https://github.com/snakemake/snakemake-wrappers.git") import os import shutil DIRS = [] # Add header to csv file with open('./result.csv', 'w') as csv_file: writer = csv.DictWriter(csv_file, fieldnames=[ 'name', 'description', 'authors', 'input_args', 'input_named_args', 'output_args', 'output_named_args', 'param_args', 'param_named_args' ]) writer.writeheader() def quantity_of_named_args(args): quantity = 0 for arg in args: if ':' in arg: quantity += 1 return quantity
def download_yara_rules_git(): if not os.listdir("rules"): git.Git().clone("https://github.com/Yara-Rules/rules") else: g = git.cmd.Git("rules") g.pull()
from dateutil import tz as dateutil_tz import git import pytz # Use a bytes mode stdin/stdout for both Python 2 and 3. if sys.version_info >= (3, ): stdin = sys.stdin.buffer stdout = sys.stdout.buffer else: stdin = sys.stdin stdout = sys.stdout attribute_regex = re.compile(r'^([^\s]*) filter=(bigstore(?:-compress)?)$') g = lambda: git.Git('.') git_directory = lambda git_instance: git_instance.rev_parse(git_dir=True) try: default_hash_function_name = g().config("bigstore.hash_function") except git.exc.GitCommandError: default_hash_function_name = 'sha1' try: toplevel_dir = g().rev_parse(show_toplevel=True) except git.exc.GitCommandError: toplevel_dir = '.' config_filename = os.path.join(toplevel_dir, '.bigstore') hash_functions = { 'md5': hashlib.md5,
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Builds the ParlAI website. """ import os import git import markdown import shutil from mdx_gfm import PartialGithubFlavoredMarkdownExtension GIT_ROOT_LEVEL = git.Git().rev_parse('--show-toplevel') WEBSITE_ROOT = os.path.join(GIT_ROOT_LEVEL, 'website') TEMPLATES = os.path.join(WEBSITE_ROOT, 'templates') OUT_DIR = os.path.join(WEBSITE_ROOT, 'build') STATIC_FILE_EXTS = { '.css', '.jpg', '.jpeg', '.png', '.json', '.jsonl', '.html', '.md' } def ghmarkdown(source): return markdown.markdown( source, extensions=[PartialGithubFlavoredMarkdownExtension()]) def _read_file(filename):
def git_clone(repoUrl, repo_path): if not os.path.exists(repo_path): git.Git().clone(repoUrl, repo_path)
# create URLS for API interaction nodeUrl = url + '/nodes/' + repoId latestUrl = nodeUrl + '/latest' latests = {} if not os.path.exists(config['Git']['path'] + repoId): repo = git.Repo.init(config['Git']['path'] + repoId, bare=True) origin = repo.create_remote('origin', url=gitUrl) else: repo = git.Repo(config['Git']['path'] + repoId) latests = latest_commits(repoId) class MyProgressPrinter(git.RemoteProgress): def update(self, op_code, cur_count, max_count=None, message=''): print(op_code, cur_count, max_count, cur_count / (max_count or 100.0), message or "NO MESSAGE") # end print('fetching commits....') for fetch_info in repo.remotes.origin.fetch(progress=MyProgressPrinter()): print("Updated %s to %s" % (fetch_info.ref, fetch_info.commit)) print('commits fetched') g = git.Git(config['Git']['path'] + repoId) if not bool(latests): requests.post(nodeUrl) # create initial node repo_commits = get_commits(g, latests) # Get a list of the latest commits post_commits(repo_commits, latests)
return counter, append_edges print( "Attenzione: Computing may take a while (several minutes). Please be patient." ) # Add source node nodes[0] = { 'name': "source_repo", 'is_leave': False, 'path': "source_repo", 'loc': 0 } # Traverse dir ret_counter, ret_edges = traverse("source_repo", 0) g = git.Git("source_repo") # Get number of commits log = g.log("--name-only", "--pretty=format:").split("\n") (files, counts) = np.unique(log, return_counts=True) commit_counts_by_path = {} for line, count in zip(files, counts): commit_counts_by_path["source_repo/" + line] = count commits_per_file = [] for key in sorted(nodes): node = nodes[key] if node['is_leave']: if node['path'] in commit_counts_by_path: commits_per_file.append(int(commit_counts_by_path[node['path']])) else:
import git for url in urls: git.Git("./").clone("git://gitorious.org/git-python/mainline.git") import shutil shutil.make_archive(output_filename, 'zip', dir_name_cloned)
def run(self): self.progressbar_show.emit(True) self.info_label.emit(translate("AddonsInstaller", "Retrieving description...")) if len(self.repos[self.idx]) == 4: desc = self.repos[self.idx][3] else: url = self.repos[self.idx][1] self.info_label.emit(translate("AddonsInstaller", "Retrieving info from ") + str(url)) if ctx: u = urllib2.urlopen(url,context=ctx) else: u = urllib2.urlopen(url) p = u.read() if sys.version_info.major >= 3 and isinstance(p, bytes): p = p.decode("utf-8") u.close() desc = re.findall("<meta name=\"description\" content=\"(.*?)\">",p) if desc: desc = desc[0] else: desc = "Unable to retrieve addon description" self.repos[self.idx].append(desc) self.addon_repos.emit(self.repos) if self.repos[self.idx][2] == 1: upd = False # checking for updates if not NOGIT: try: import git except: pass else: repo = self.repos[self.idx] clonedir = FreeCAD.ConfigGet("UserAppData") + os.sep + "Mod" + os.sep + repo[0] if os.path.exists(clonedir): if not os.path.exists(clonedir + os.sep + '.git'): # Repair addon installed with raw download bare_repo = git.Repo.clone_from(repo[1], clonedir + os.sep + '.git', bare=True) try: with bare_repo.config_writer() as cw: cw.set('core', 'bare', False) except AttributeError: FreeCAD.Console.PrintWarning(translate("AddonsInstaller", "Outdated GitPython detected, consider upgrading with pip.\n")) cw = bare_repo.config_writer() cw.set('core', 'bare', False) del cw repo = git.Repo(clonedir) repo.head.reset('--hard') gitrepo = git.Git(clonedir) gitrepo.fetch() if "git pull" in gitrepo.status(): upd = True if upd: message = "<strong>" + translate("AddonsInstaller", "An update is available for this addon.") + "</strong><br>" + desc + ' - <a href="' + self.repos[self.idx][1] + '"><span style="word-wrap: break-word;width:15em;text-decoration: underline; color:#0000ff;">' + self.repos[self.idx][1] + '</span></a>' else: message = "<strong>" + translate("AddonsInstaller", "This addon is already installed.") + "</strong><br>" + desc + ' - <a href="' + self.repos[self.idx][1] + '"><span style="word-wrap: break-word;width:15em;text-decoration: underline; color:#0000ff;">' + self.repos[self.idx][1] + '</span></a>' else: message = desc + ' - <a href="' + self.repos[self.idx][1] + '"><span style="word-wrap: break-word;width:15em;text-decoration: underline; color:#0000ff;">' + self.repos[self.idx][1] + '</span></a>' self.info_label.emit( message ) self.progressbar_show.emit(False) self.stop = True
def _get_highest_semver_tag(repo, target_commit, major_version, all_reachable=False): """ Get the highest semantic version tag related to the input commit. :param Git.Repo repo: the Git repository object to search :param int major_version: the major version of the Go module as in the go.mod file to use as a filter for major version tags :param bool all_reachable: if False, the search is constrained to the input commit. If True, then the search is constrained to the input commit and preceding commits. :return: the highest semantic version tag if one is found :rtype: git.Tag """ try: g = git.Git(repo.working_dir) if all_reachable: # Get all the tags on the input commit and all that precede it. # This is based on: # https://github.com/golang/go/blob/0ac8739ad5394c3fe0420cf53232954fefb2418f/src/cmd/go/internal/modfetch/codehost/git.go#L659-L695 cmd = [ "git", "for-each-ref", "--format", "%(refname:lstrip=-1)", "refs/tags", "--merged", target_commit.hexsha, ] else: # Get the tags that point to this commit cmd = ["git", "tag", "--points-at", target_commit.hexsha] tag_names = g.execute(cmd).splitlines() except git.GitCommandError: msg = f"Failed to get the tags associated with the reference {target_commit.hexsha}" log.exception(msg) raise CachitoError(msg) not_semver_tag_msg = "%s is not a semantic version tag" highest = None for tag_name in tag_names: if not tag_name.startswith("v"): log.debug(not_semver_tag_msg, tag_name) continue try: # Exclude the 'v' prefix since this is required by Go, but it is seen as invalid by # the semver Python package parsed_version = semver.parse_version_info(tag_name[1:]) except ValueError: log.debug(not_semver_tag_msg, tag_name) continue # If the major version of the semantic version tag doesn't match the Go module's major # version, then ignore it if parsed_version.major != major_version: continue if highest is None: highest = tag_name else: highest_version = semver.parse_version_info(highest[1:]) if parsed_version > highest_version: highest = tag_name if highest: return repo.tags[highest] return None