repos: Remove ctx parameter from repo functions and their callers

We can use the global context instead.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Jan Kiszka 2018-08-24 19:18:06 +02:00 committed by Daniel Wagner
parent 7937c1963e
commit b349f86457
3 changed files with 24 additions and 22 deletions

View File

@ -197,7 +197,7 @@ class ReposFetch(Command):
return 'repos_fetch' return 'repos_fetch'
def execute(self, ctx): def execute(self, ctx):
repos_fetch(ctx, ctx.config.get_repos()) repos_fetch(ctx.config.get_repos())
class ReposApplyPatches(Command): class ReposApplyPatches(Command):
@ -209,7 +209,7 @@ class ReposApplyPatches(Command):
return 'repos_apply_patches' return 'repos_apply_patches'
def execute(self, ctx): def execute(self, ctx):
repos_apply_patches(ctx, ctx.config.get_repos()) repos_apply_patches(ctx.config.get_repos())
class ReposCheckout(Command): class ReposCheckout(Command):
@ -222,7 +222,7 @@ class ReposCheckout(Command):
def execute(self, ctx): def execute(self, ctx):
for repo in ctx.config.get_repos(): for repo in ctx.config.get_repos():
repo.checkout(ctx) repo.checkout()
class SetupRepos(Command): class SetupRepos(Command):
@ -255,10 +255,10 @@ class SetupRepos(Command):
for repo_name in missing_repo_names for repo_name in missing_repo_names
if repo_name in ctx.config.repo_dict] if repo_name in ctx.config.repo_dict]
repos_fetch(ctx, missing_repos) repos_fetch(missing_repos)
for repo in missing_repos: for repo in missing_repos:
repo.checkout(ctx) repo.checkout()
ctx.config.repo_dict = ctx.config._get_repo_dict() ctx.config.repo_dict = ctx.config._get_repo_dict()
@ -272,10 +272,10 @@ class SetupRepos(Command):
# now fetch everything with complete config and check out layers # now fetch everything with complete config and check out layers
# except if keep_config is set # except if keep_config is set
if not ctx.keep_config: if not ctx.keep_config:
repos_fetch(ctx, ctx.config.get_repos()) repos_fetch(ctx.config.get_repos())
for repo in ctx.config.get_repos(): for repo in ctx.config.get_repos():
repo.checkout(ctx) repo.checkout()
logging.debug('Configuration from config file:\n%s', logging.debug('Configuration from config file:\n%s',
pprint.pformat(ctx.config._config)) pprint.pformat(ctx.config._config))

View File

@ -168,7 +168,7 @@ def find_program(paths, name):
return None return None
def repos_fetch(config, repos): def repos_fetch(repos):
""" """
Fetches the list of repositories to the kas_work_dir. Fetches the list of repositories to the kas_work_dir.
""" """
@ -176,9 +176,9 @@ def repos_fetch(config, repos):
for repo in repos: for repo in repos:
if not hasattr(asyncio, 'ensure_future'): if not hasattr(asyncio, 'ensure_future'):
# pylint: disable=no-member,deprecated-method # pylint: disable=no-member,deprecated-method
task = asyncio.async(repo.fetch_async(config)) task = asyncio.async(repo.fetch_async())
else: else:
task = asyncio.ensure_future(repo.fetch_async(config)) task = asyncio.ensure_future(repo.fetch_async())
tasks.append(task) tasks.append(task)
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
@ -189,7 +189,7 @@ def repos_fetch(config, repos):
sys.exit(task.result()) sys.exit(task.result())
def repos_apply_patches(config, repos): def repos_apply_patches(repos):
""" """
Applies the patches to the repositories. Applies the patches to the repositories.
""" """
@ -197,9 +197,9 @@ def repos_apply_patches(config, repos):
for repo in repos: for repo in repos:
if not hasattr(asyncio, 'ensure_future'): if not hasattr(asyncio, 'ensure_future'):
# pylint: disable=no-member,deprecated-method # pylint: disable=no-member,deprecated-method
task = asyncio.async(repo.apply_patches_async(config)) task = asyncio.async(repo.apply_patches_async())
else: else:
task = asyncio.ensure_future(repo.apply_patches_async(config)) task = asyncio.ensure_future(repo.apply_patches_async())
tasks.append(task) tasks.append(task)
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()

View File

@ -146,7 +146,7 @@ class RepoImpl(Repo):
""" """
@asyncio.coroutine @asyncio.coroutine
def fetch_async(self, ctx): def fetch_async(self):
""" """
Start asynchronous repository fetch. Start asynchronous repository fetch.
""" """
@ -155,12 +155,13 @@ class RepoImpl(Repo):
if not os.path.exists(self.path): if not os.path.exists(self.path):
os.makedirs(os.path.dirname(self.path), exist_ok=True) os.makedirs(os.path.dirname(self.path), exist_ok=True)
sdir = os.path.join(ctx.kas_repo_ref_dir or '', sdir = os.path.join(get_context().kas_repo_ref_dir or '',
self.qualified_name) self.qualified_name)
logging.debug('Looking for repo ref dir in %s', sdir) logging.debug('Looking for repo ref dir in %s', sdir)
(retc, _) = yield from run_cmd_async(self.clone_cmd(sdir, ctx), (retc, _) = yield from run_cmd_async(
cwd=ctx.kas_work_dir) self.clone_cmd(sdir),
cwd=get_context().kas_work_dir)
if retc == 0: if retc == 0:
logging.info('Repository %s cloned', self.name) logging.info('Repository %s cloned', self.name)
return retc return retc
@ -190,7 +191,7 @@ class RepoImpl(Repo):
logging.info('Repository %s updated', self.name) logging.info('Repository %s updated', self.name)
return 0 return 0
def checkout(self, _): def checkout(self):
""" """
Checks out the correct revision of the repo. Checks out the correct revision of the repo.
""" """
@ -217,7 +218,7 @@ class RepoImpl(Repo):
run_cmd(self.checkout_cmd(), cwd=self.path) run_cmd(self.checkout_cmd(), cwd=self.path)
@asyncio.coroutine @asyncio.coroutine
def apply_patches_async(self, ctx): def apply_patches_async(self):
""" """
Applies patches to repository asynchronously. Applies patches to repository asynchronously.
""" """
@ -225,7 +226,8 @@ class RepoImpl(Repo):
return 0 return 0
for patch in self._patches: for patch in self._patches:
other_repo = ctx.config.repo_dict.get(patch['repo'], None) other_repo = get_context().config.repo_dict.get(patch['repo'],
None)
if not other_repo: if not other_repo:
logging.warning('Could not find referenced repo. ' logging.warning('Could not find referenced repo. '
@ -274,9 +276,9 @@ class GitRepo(RepoImpl):
""" """
# pylint: disable=no-self-use,missing-docstring # pylint: disable=no-self-use,missing-docstring
def clone_cmd(self, gitsrcdir, ctx): def clone_cmd(self, gitsrcdir):
cmd = ['git', 'clone', '-q', self.url, self.path] cmd = ['git', 'clone', '-q', self.url, self.path]
if ctx.kas_repo_ref_dir and os.path.exists(gitsrcdir): if get_context().kas_repo_ref_dir and os.path.exists(gitsrcdir):
cmd.extend(['--reference', gitsrcdir]) cmd.extend(['--reference', gitsrcdir])
return cmd return cmd