From 987698d7500fda143d047342438b009f0897d079 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Tue, 25 Jul 2017 17:54:04 -0400 Subject: [PATCH] Cleaned up some code; removed the tag and commit tracking features for now --- lib/Formula.py | 10 +++------- lib/FormulaRepo.py | 32 ++++++++++++-------------------- salt-formula-manager.py | 4 ++-- 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/lib/Formula.py b/lib/Formula.py index ea3e9cc..814d5a7 100644 --- a/lib/Formula.py +++ b/lib/Formula.py @@ -49,11 +49,7 @@ class Formula(): # checks to see if a branch, tag, or commit to track has been defined def get_tracking_state(self): - if 'track_branch' in self.formula_def: - return 0, self.formula_def['track_branch'] - elif 'track_tag' in self.formula_def: - return 1, self.formula_def['track_tag'] - elif 'track_commit' in self.formula_def: - return 2, self.formula_def['track_commit'] + if 'git_branch' in self.formula_def: + return self.formula_def['git_branch'] else: - return 0, False + return False diff --git a/lib/FormulaRepo.py b/lib/FormulaRepo.py index cf9d6a1..0d508f1 100644 --- a/lib/FormulaRepo.py +++ b/lib/FormulaRepo.py @@ -27,32 +27,24 @@ class FormulaRepo(): self.repo = Repo(self.repo_path) # check if the repo is up to date - def check_tracking_info(self, tracking_key, tracking_value): - if tracking_key == 0: + def check_tracking_info(self, branch): + if branch != False: # tracking a specific branch on the repo - if tracking_value != False: - # check to make sure that the given branch name actually exists first - if not tracking_value in self.repo.branches: - print('%s is not an existing branch name for %s - please fix this.' % (tracking_value, self.repo_path)) - sys.exit(1) + # check to make sure that the given branch name actually exists first + if not tracking_value in self.repo.branches: + print('%s is not an existing branch name for %s - please fix this.' % (tracking_value, self.repo_path)) + sys.exit(1) - repo_branch = self.repo.head.reference - # check to make sure that the current tracked branch is, in fact, what we want - if repo_branch != tracking_value: - self.repo.head.reference = repo_branch + repo_branch = self.repo.head.reference + # check to make sure that the current tracked branch is, in fact, what we want + if repo_branch != tracking_value: + self.repo.head.reference = repo_branch # let the user know which branch we're using print('For %s, we\'re using the %s branch.' % (self.repo_path, self.repo.head.reference)) - elif tracking_key == 1: - # tracking a specific tag on the repo - print('Tracking a tag') - elif tracking_key == 2: - # tracking a specific commit on the repo - print('Tracking a commit') else: - # we shouldn't get here... - print('So... somehow %s got a tracking key of %d, but that is not a valid tracking key!' % (self.repo_path, tracking_key)) - sys.exit(1) + # no branch was specified, so we're going with what's there + print('Using the default/current branch for %s' % (self.repo_path)) # pull any new updates for the repo diff --git a/salt-formula-manager.py b/salt-formula-manager.py index 474f42d..c5528cd 100644 --- a/salt-formula-manager.py +++ b/salt-formula-manager.py @@ -44,9 +44,9 @@ def get_formulas(formulas, formulas_dir, formulas_url): formula_repo.retrieve() # get the repo tracking information from the formula definition - tracking_key, tracking_value = formula.get_tracking_state() + tracking_branch = formula.get_tracking_state() # make sure our formula's repo is up-to-date with the latest tracked version - formula_repo.check_tracking_info(tracking_key, tracking_value) + formula_repo.check_tracking_info(tracking_branch) # pull any new commits for the repo formula_repo.pull_updates()