Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
p = os.path.join(path, line.split(' #')[0].rstrip())
if os.path.isfile(p):
my_patches.append((p, patch['id']))
else:
raise FileNotFoundError(p)
else:
logging.error('Could not find patch. '
'(patch path: %s, repo: %s, patch entry: %s)',
path,
self.name,
patch['id'])
return 1
for (path, patch_id) in my_patches:
cmd = self.apply_patches_file_cmd(path)
(retc, output) = await run_cmd_async(cmd, cwd=self.path)
if retc:
logging.error('Could not apply patch. Please fix repos and '
'patches. (patch path: %s, repo: %s, patch '
'entry: %s, vcs output: %s)',
path, self.name, patch_id, output)
return 1
else:
logging.info('Patch applied. '
'(patch path: %s, repo: %s, patch entry: %s)',
path, self.name, patch_id)
cmd = self.add_cmd()
(retc, output) = await run_cmd_async(cmd, cwd=self.path)
if retc:
logging.error('Could not add patched files. '
'repo: %s, vcs output: %s)',
for (path, patch_id) in my_patches:
cmd = self.apply_patches_file_cmd(path)
(retc, output) = await run_cmd_async(cmd, cwd=self.path)
if retc:
logging.error('Could not apply patch. Please fix repos and '
'patches. (patch path: %s, repo: %s, patch '
'entry: %s, vcs output: %s)',
path, self.name, patch_id, output)
return 1
else:
logging.info('Patch applied. '
'(patch path: %s, repo: %s, patch entry: %s)',
path, self.name, patch_id)
cmd = self.add_cmd()
(retc, output) = await run_cmd_async(cmd, cwd=self.path)
if retc:
logging.error('Could not add patched files. '
'repo: %s, vcs output: %s)',
self.name, output)
return 1
cmd = self.commit_cmd()
(retc, output) = await run_cmd_async(cmd, cwd=self.path)
if retc:
logging.error('Could not commit patch changes. '
'repo: %s, vcs output: %s)',
self.name, output)
return 1
return 0
liveupdate=False)
if retc != 0:
logging.info('Changing remote URL to %s failed with error: %s',
self.effective_url, output.strip())
return retc
except NotImplementedError:
logging.warning('Repo implementation does not support changing '
'the remote url.')
# take what came out of clone and stick to that forever
if self.refspec is None:
return 0
if not get_context().update:
# Does refspec exist in the current repository?
(retc, output) = await run_cmd_async(self.contains_refspec_cmd(),
cwd=self.path,
fail=False,
liveupdate=False)
if retc == 0:
logging.info('Repository %s already contains %s as %s',
self.name, self.refspec, output.strip())
return retc
# Try to fetch if refspec is missing or if --update argument was passed
(retc, output) = await run_cmd_async(self.fetch_cmd(),
cwd=self.path,
fail=False)
if retc:
logging.warning('Could not update repository %s: %s',
self.name, output)
else:
if self.refspec is None:
return 0
if not get_context().update:
# Does refspec exist in the current repository?
(retc, output) = await run_cmd_async(self.contains_refspec_cmd(),
cwd=self.path,
fail=False,
liveupdate=False)
if retc == 0:
logging.info('Repository %s already contains %s as %s',
self.name, self.refspec, output.strip())
return retc
# Try to fetch if refspec is missing or if --update argument was passed
(retc, output) = await run_cmd_async(self.fetch_cmd(),
cwd=self.path,
fail=False)
if retc:
logging.warning('Could not update repository %s: %s',
self.name, output)
else:
logging.info('Repository %s updated', self.name)
return 0
return 1
else:
logging.info('Patch applied. '
'(patch path: %s, repo: %s, patch entry: %s)',
path, self.name, patch_id)
cmd = self.add_cmd()
(retc, output) = await run_cmd_async(cmd, cwd=self.path)
if retc:
logging.error('Could not add patched files. '
'repo: %s, vcs output: %s)',
self.name, output)
return 1
cmd = self.commit_cmd()
(retc, output) = await run_cmd_async(cmd, cwd=self.path)
if retc:
logging.error('Could not commit patch changes. '
'repo: %s, vcs output: %s)',
self.name, output)
return 1
return 0
os.makedirs(os.path.dirname(self.path), exist_ok=True)
sdir = os.path.join(get_context().kas_repo_ref_dir or '',
self.qualified_name)
logging.debug('Looking for repo ref dir in %s', sdir)
(retc, _) = await run_cmd_async(
self.clone_cmd(sdir),
cwd=get_context().kas_work_dir)
if retc == 0:
logging.info('Repository %s cloned', self.name)
return retc
# Make sure the remote origin is set to the value
# in the kas file to avoid suprises
try:
(retc, output) = await run_cmd_async(
self.set_remote_url_cmd(),
cwd=self.path,
fail=False,
liveupdate=False)
if retc != 0:
logging.info('Changing remote URL to %s failed with error: %s',
self.effective_url, output.strip())
return retc
except NotImplementedError:
logging.warning('Repo implementation does not support changing '
'the remote url.')
# take what came out of clone and stick to that forever
if self.refspec is None:
return 0
async def fetch_async(self):
"""
Starts asynchronous repository fetch.
"""
if self.operations_disabled:
return 0
if not os.path.exists(self.path):
os.makedirs(os.path.dirname(self.path), exist_ok=True)
sdir = os.path.join(get_context().kas_repo_ref_dir or '',
self.qualified_name)
logging.debug('Looking for repo ref dir in %s', sdir)
(retc, _) = await run_cmd_async(
self.clone_cmd(sdir),
cwd=get_context().kas_work_dir)
if retc == 0:
logging.info('Repository %s cloned', self.name)
return retc
# Make sure the remote origin is set to the value
# in the kas file to avoid suprises
try:
(retc, output) = await run_cmd_async(
self.set_remote_url_cmd(),
cwd=self.path,
fail=False,
liveupdate=False)
if retc != 0:
logging.info('Changing remote URL to %s failed with error: %s',
async def apply_patches_async(self):
"""
Applies patches to a repository asynchronously.
"""
if self.operations_disabled or not self._patches:
return 0
(retc, _) = await run_cmd_async(self.prepare_patches_cmd(),
cwd=self.path)
if retc:
return retc
my_patches = []
for patch in self._patches:
other_repo = get_context().config.repo_dict.get(patch['repo'],
None)
if not other_repo:
logging.error('Could not find referenced repo. '
'(missing repo: %s, repo: %s, '
'patch entry: %s)',
patch['repo'],
self.name,