Skip to content

Commit

Permalink
Merge pull request #376 from JrGoodle/plugins
Browse files Browse the repository at this point in the history
Add example plugin
  • Loading branch information
JrGoodle committed Nov 6, 2017
2 parents f847415 + be1caf4 commit 643479b
Show file tree
Hide file tree
Showing 20 changed files with 293 additions and 91 deletions.
3 changes: 2 additions & 1 deletion .idea/clowder.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 8 additions & 14 deletions clowder/clowder/clowder_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from termcolor import cprint

from clowder.error.clowder_yaml_error import ClowderYAMLError
from clowder.model.defaults import Defaults
from clowder.model.group import Group
from clowder.model.source import Source
from clowder.yaml.loading import load_yaml
Expand Down Expand Up @@ -120,11 +121,9 @@ def get_yaml(self):
:rtype: dict
"""

groups_yaml = [g.get_yaml() for g in self.groups]
sources_yaml = [s.get_yaml() for s in self.sources]
return {'defaults': self.defaults,
'sources': sources_yaml,
'groups': groups_yaml}
return {'defaults': self.defaults.get_yaml(),
'sources': [s.get_yaml() for s in self.sources],
'groups': [g.get_yaml() for g in self.groups]}

def get_yaml_resolved(self):
"""Return python object representation for resolved yaml
Expand All @@ -133,20 +132,15 @@ def get_yaml_resolved(self):
:rtype: dict
"""

groups_yaml = [g.get_yaml_resolved() for g in self.groups]
sources_yaml = [s.get_yaml() for s in self.sources]
return {'defaults': self.defaults,
'sources': sources_yaml,
'groups': groups_yaml}
return {'defaults': self.defaults.get_yaml(),
'sources': [s.get_yaml() for s in self.sources],
'groups': [g.get_yaml_resolved() for g in self.groups]}

def _load_yaml(self):
"""Load clowder.yaml"""
try:
yaml = load_yaml(self.root_directory)
self.defaults = yaml['defaults']
if 'depth' not in self.defaults:
self.defaults['depth'] = 0

self.defaults = Defaults(yaml['defaults'])
self.sources = [Source(s) for s in yaml['sources']]
for group in yaml['groups']:
self.groups.append(Group(self.root_directory, group, self.defaults, self.sources))
Expand Down
2 changes: 1 addition & 1 deletion clowder/clowder/clowder_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def link(self, version=None):
yaml_file = os.path.join(self.root_directory, relative_path)

if not os.path.isfile(yaml_file):
print(path_output + " doesn't seem to exist\n")
print('\n' + path_output + " doesn't seem to exist\n")
sys.exit(1)

yaml_symlink = os.path.join(self.root_directory, 'clowder.yaml')
Expand Down
52 changes: 52 additions & 0 deletions clowder/clowder/model/defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
"""Representation of clowder.yaml defaults
.. codeauthor:: Joe Decapo <joe@polka.cat>
"""


class Defaults(object):
"""clowder.yaml Defaults model class
:ivar str ref: Default ref
:ivar str remote: Default remote name
:ivar str source: Default source name
:ivar str protocol: Default git protocol
:ivar int depth: Default depth
:ivar bool recursive: Default recursive value
:ivar str timestamp_author: Default timestamp author
"""

def __init__(self, defaults):
"""Defaults __init__
:param dict defaults: Parsed YAML python object for defaults
"""

self.ref = defaults["ref"]
self.protocol = defaults["protocol"]
self.remote = defaults["remote"]
self.source = defaults["source"]
self.depth = defaults.get("depth", 0)
self.recursive = defaults.get("recursive", False)
self.timestamp_author = defaults.get("timestamp_author", None)

def get_yaml(self):
"""Return python object representation for saving yaml
:return: YAML python object
:rtype: dict
"""

defaults = {'ref': self.ref,
'recursive': self.recursive,
'remote': self.remote,
'source': self.source,
'depth': self.depth,
'protocol': self.protocol}

if self.timestamp_author:
defaults['timestamp_author'] = self.timestamp_author

return defaults
2 changes: 1 addition & 1 deletion clowder/clowder/model/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Fork(object):
:ivar str name: Project name
:ivar str path: Project relative path
:ivar Fork fork: Project's associated Fork
:ivar str remote_name: Git remote name
"""

def __init__(self, fork, root_directory, path, source):
Expand Down
14 changes: 7 additions & 7 deletions clowder/clowder/model/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ def __init__(self, root_directory, group, defaults, sources):
:param str root_directory: Root directory of clowder projects
:param dict group: Parsed YAML python object for group
:param dict defaults: Parsed YAML python object for defaults
:param Defaults defaults: Defaults instance
:param list[Source] sources: List of Source instances
"""

self.name = group['name']
self.depth = group.get('depth', defaults['depth'])
self.recursive = group.get('recursive', defaults.get('recursive', False))
self.timestamp_author = group.get('timestamp_author', defaults.get('timestamp_author', None))
self.ref = group.get('ref', defaults['ref'])
self.remote_name = group.get('remote', defaults['remote'])
source_name = group.get('source', defaults['source'])
self.depth = group.get('depth', defaults.depth)
self.recursive = group.get('recursive', defaults.recursive)
self.timestamp_author = group.get('timestamp_author', defaults.timestamp_author)
self.ref = group.get('ref', defaults.ref)
self.remote_name = group.get('remote', defaults.remote)
source_name = group.get('source', defaults.source)

for source in sources:
if source.name == source_name:
Expand Down

0 comments on commit 643479b

Please sign in to comment.