-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify implementation of track and team repositories
Closes #308
- Loading branch information
1 parent
69c06e9
commit 4105331
Showing
5 changed files
with
354 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import os | ||
import sys | ||
import logging | ||
|
||
from esrally import exceptions | ||
from esrally.utils import git, console, versions | ||
|
||
logger = logging.getLogger("rally.repo") | ||
|
||
|
||
class RallyRepository: | ||
""" | ||
Manages Rally resources (e.g. teams or tracks). | ||
""" | ||
|
||
def __init__(self, remote_url, root_dir, repo_name, resource_name, offline, fetch=True): | ||
# If no URL is found, we consider this a local only repo (but still require that it is a git repo) | ||
self.url = remote_url | ||
self.remote = self.url is not None and self.url.strip() != "" | ||
self.repo_dir = os.path.join(root_dir, repo_name) | ||
self.resource_name = resource_name | ||
self.offline = offline | ||
if self.remote and not self.offline and fetch: | ||
# a normal git repo with a remote | ||
if not git.is_working_copy(self.repo_dir): | ||
git.clone(src=self.repo_dir, remote=self.url) | ||
else: | ||
try: | ||
git.fetch(src=self.repo_dir) | ||
except exceptions.SupplyError: | ||
console.warn("Could not update %s. Continuing with your locally available state." % self.resource_name, logger=logger) | ||
else: | ||
if not git.is_working_copy(self.repo_dir): | ||
raise exceptions.SystemSetupError("[{src}] must be a git repository.\n\nPlease run:\ngit -C {src} init" | ||
.format(src=self.repo_dir)) | ||
|
||
def update(self, distribution_version): | ||
try: | ||
if self.remote and not self.offline: | ||
branch = versions.best_match(git.branches(self.repo_dir, remote=self.remote), distribution_version) | ||
if branch: | ||
# Allow uncommitted changes iff we do not have to change the branch | ||
logger.info( | ||
"Checking out [%s] in [%s] for distribution version [%s]." % (branch, self.repo_dir, distribution_version)) | ||
git.checkout(self.repo_dir, branch=branch) | ||
logger.info("Rebasing on [%s] in [%s] for distribution version [%s]." % (branch, self.repo_dir, distribution_version)) | ||
try: | ||
git.rebase(self.repo_dir, branch=branch) | ||
except exceptions.SupplyError: | ||
logger.exception("Cannot rebase due to local changes in [%s]" % self.repo_dir) | ||
console.warn( | ||
"Local changes in [%s] prevent %s update from remote. Please commit your changes." % | ||
(self.resource_name, self.repo_dir)) | ||
return | ||
else: | ||
msg = "Could not find %s remotely for distribution version [%s]. Trying to find %s locally." % \ | ||
(self.resource_name, distribution_version, self.resource_name) | ||
logger.warning(msg) | ||
branch = versions.best_match(git.branches(self.repo_dir, remote=False), distribution_version) | ||
if branch: | ||
logger.info("Checking out [%s] in [%s] for distribution version [%s]." % (branch, self.repo_dir, distribution_version)) | ||
git.checkout(self.repo_dir, branch=branch) | ||
else: | ||
raise exceptions.SystemSetupError("Cannot find %s for distribution version %s" % (self.resource_name, distribution_version)) | ||
except exceptions.SupplyError: | ||
tb = sys.exc_info()[2] | ||
raise exceptions.DataError("Cannot update [%s] in [%s]." % (self.resource_name, self.repo_dir)).with_traceback(tb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.