Don't use self.options

parent 2bfadf5e
......@@ -37,20 +37,19 @@ class Recipe(object):
"""Clone a git repository."""
def __init__(self, buildout, name, options):
options.setdefault('branch', GIT_DEFAULT_BRANCH_NAME)
options.setdefault('revision', '')
options.setdefault('branch', '')
options.setdefault('develop', 'false')
options.setdefault('git-command', 'git')
options.setdefault('location',
os.path.join(
buildout['buildout']['parts-directory'],
name
)
)
self.options = options
if options['revision'] and options['branch']:
self.url = options.get('url')
self.branch = options.get('branch', GIT_DEFAULT_BRANCH_NAME)
self.revision = options.get('revision')
self.git_command = options.get('git-command', 'git')
self.location = options.get('location',
os.path.join(buildout['buildout']['parts-directory'], name))
if options.get('develop') in TRUE_VALUES:
self.develop = True
if not self.url:
raise ValueError('url parameter is mandatory.')
if self.revision and self.branch:
# revision and branch options are incompatible
raise ValueError('revision and branch parameters are set but are'
'incompatible. Please specify only one of them.')
......@@ -58,39 +57,48 @@ class Recipe(object):
def gitReset(self, revision=None):
"""Operates git reset on the repository."""
command = [self.options['git-command'], 'reset', '--hard']
command = [self.git_command, 'reset', '--hard']
if revision:
command.append(revision)
check_call(command, cwd=self.options['location'])
check_call(command, cwd=self.location)
def install(self):
""" Do a git clone. If revision is specified, reset to it."""
if not os.path.exists(self.options['location']):
git_clone_command = [self.options['git-command'], 'clone',
self.options['url'],
self.options['location']]
if self.options['branch']:
git_clone_command.extend(['--branch', self.options['branch']])
"""
Do a git clone.
If branch is specified, checkout to it.
If revision is specified, reset to it.
"""
if not os.path.exists(self.location):
git_clone_command = [self.git_command, 'clone',
self.url,
self.location]
if self.branch:
git_clone_command.extend(['--branch', self.branch])
check_call(git_clone_command)
if self.options['revision']:
self.gitReset(self.options['revision'])
if self.revision:
self.gitReset(self.revision)
return [self.options['location']]
return [self.location]
def update(self):
check_call([self.options['git-command'], 'fetch', '--all'],
cwd=self.options['location'])
"""
Do a git fetch.
If user doesn't develop, reset to remote HEAD (or revision or branch if
specified.)
"""
check_call([self.git_command, 'fetch', '--all'], cwd=self.location)
# If develop parameter is set, don't reset/update.
# Otherwise, reset --hard
if not self.options.get('develop') in TRUE_VALUES:
if self.options['revision']:
self.gitReset(self.options['revision'])
elif self.options['branch']:
if not self.develop:
if self.revision:
self.gitReset(self.revision)
elif self.branch:
self.gitReset('%s/%s' % (
GIT_DEFAULT_REMOTE_NAME, self.options['branch']))
GIT_DEFAULT_REMOTE_NAME, self.branch))
else:
self.gitReset('%s/%s' % (
GIT_DEFAULT_REMOTE_NAME, GIT_DEFAULT_BRANCH_NAME))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment