2-spaces indentation

parent 9f7e9661
...@@ -34,63 +34,63 @@ GIT_DEFAULT_BRANCH_NAME = 'master' ...@@ -34,63 +34,63 @@ GIT_DEFAULT_BRANCH_NAME = 'master'
TRUE_VALUES = ['y', 'yes', '1', 'true'] TRUE_VALUES = ['y', 'yes', '1', 'true']
class Recipe(object): class Recipe(object):
"""Clone a git repository.""" """Clone a git repository."""
def __init__(self, buildout, name, options): def __init__(self, buildout, name, options):
options.setdefault('branch', GIT_DEFAULT_BRANCH_NAME) options.setdefault('branch', GIT_DEFAULT_BRANCH_NAME)
options.setdefault('revision', '') options.setdefault('revision', '')
options.setdefault('branch', '') options.setdefault('branch', '')
options.setdefault('develop', 'false') options.setdefault('develop', 'false')
options.setdefault('git-command', 'git') options.setdefault('git-command', 'git')
options.setdefault('location', options.setdefault('location',
os.path.join( os.path.join(
buildout['buildout']['parts-directory'], buildout['buildout']['parts-directory'],
name name
) )
) )
self.options = options self.options = options
if options['revision'] and options['branch']: if options['revision'] and options['branch']:
# revision and branch options are incompatible # revision and branch options are incompatible
raise ValueError('revision and branch parameters are set but are' raise ValueError('revision and branch parameters are set but are'
'incompatible. Please specify only one of them.') 'incompatible. Please specify only one of them.')
def gitReset(self, revision=None): def gitReset(self, revision=None):
"""Operates git reset on the repository.""" """Operates git reset on the repository."""
command = [self.options['git-command'], 'reset', '--hard'] command = [self.options['git-command'], 'reset', '--hard']
if revision: if revision:
command.append(revision) command.append(revision)
check_call(command, cwd=self.options['location']) check_call(command, cwd=self.options['location'])
def install(self): def install(self):
""" Do a git clone. If revision is specified, reset to it.""" """ Do a git clone. If revision is specified, reset to it."""
if not os.path.exists(self.options['location']): if not os.path.exists(self.options['location']):
git_clone_command = [self.options['git-command'], 'clone', git_clone_command = [self.options['git-command'], 'clone',
self.options['url'], self.options['url'],
self.options['location']] self.options['location']]
if self.options['branch']: if self.options['branch']:
git_clone_command.extend(['--branch', self.options['branch']]) git_clone_command.extend(['--branch', self.options['branch']])
check_call(git_clone_command) check_call(git_clone_command)
if self.options['revision']: if self.options['revision']:
self.gitReset(self.options['revision']) self.gitReset(self.options['revision'])
return [self.options['location']] return [self.options['location']]
def update(self): def update(self):
check_call([self.options['git-command'], 'fetch', '--all'], check_call([self.options['git-command'], 'fetch', '--all'],
cwd=self.options['location']) cwd=self.options['location'])
# If develop parameter is set, don't reset/update. # If develop parameter is set, don't reset/update.
# Otherwise, reset --hard # Otherwise, reset --hard
if not self.options.get('develop') in TRUE_VALUES: if not self.options.get('develop') in TRUE_VALUES:
if self.options['revision']: if self.options['revision']:
self.gitReset(self.options['revision']) self.gitReset(self.options['revision'])
elif self.options['branch']: elif self.options['branch']:
self.gitReset('%s/%s' % ( self.gitReset('%s/%s' % (
GIT_DEFAULT_REMOTE_NAME, self.options['branch'])) GIT_DEFAULT_REMOTE_NAME, self.options['branch']))
else: else:
self.gitReset('%s/%s' % ( self.gitReset('%s/%s' % (
GIT_DEFAULT_REMOTE_NAME, GIT_DEFAULT_BRANCH_NAME)) 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