Skip to content

Commit

Permalink
Merge pull request #530 from JrGoodle/protocol-enum
Browse files Browse the repository at this point in the history
Add git protocol enum
  • Loading branch information
JrGoodle committed May 23, 2020
2 parents f98eb4e + c5c28ce commit 8f8d2e4
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/clowder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

import logging
# import logging
import os
from pathlib import Path
from typing import Optional
Expand All @@ -22,7 +22,7 @@

CURRENT_DIR = Path.cwd()
CLOWDER_CONFIG_DIR = Path.home() / '.config' / 'clowder'
CLOWDER_CONFIG_YAML = Path(CLOWDER_CONFIG_DIR) / 'clowder.config.yaml'
CLOWDER_CONFIG_YAML = CLOWDER_CONFIG_DIR / 'clowder.config.yaml'
CLOWDER_DIR: Optional[Path] = None
CLOWDER_REPO_DIR: Optional[Path] = None
CLOWDER_REPO_VERSIONS_DIR: Optional[Path] = None
Expand Down
5 changes: 3 additions & 2 deletions src/clowder/clowder_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import clowder.util.formatting as fmt
from clowder import CLOWDER_DIR, CLOWDER_REPO_DIR, CLOWDER_YAML, CURRENT_DIR
from clowder.error import ClowderError, ClowderExit
from clowder.git.project_repo import ProjectRepo
from clowder.git import ProjectRepo
from clowder.git.util import existing_git_repository
from clowder.util.clowder_utils import link_clowder_yaml
from clowder.util.connectivity import is_offline
Expand Down Expand Up @@ -127,7 +127,8 @@ def print_status(fetch: bool = False) -> None:
print(' - Fetch upstream changes for clowder repo')
repo.fetch(clowder_repo_remote)

project_output = repo.format_project_string('.clowder')
clowder_path = Path('.clowder')
project_output = repo.format_project_string(clowder_path)
current_ref_output = repo.format_project_ref_string()

if CLOWDER_YAML is None or not CLOWDER_YAML.is_symlink():
Expand Down
14 changes: 14 additions & 0 deletions src/clowder/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,17 @@
.. codeauthor:: Joe Decapo <joe@polka.cat>
"""

from enum import Enum, unique

from .git_repo import GitRepo
from .project_repo import ProjectRepo
from .project_repo_recursive import ProjectRepoRecursive


@unique
class GitProtocol(Enum):
"""Git protocol enum"""

SSH = "ssh"
HTTPS = "https"
File renamed without changes.
2 changes: 1 addition & 1 deletion src/clowder/git/project_repo_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from clowder.error import ClowderGitError
from clowder.util.file_system import remove_directory

from .repo import GitRepo
from .git_repo import GitRepo
from .util import (
existing_git_repository,
not_detached
Expand Down
7 changes: 4 additions & 3 deletions src/clowder/model/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

from clowder.git import GitProtocol
from clowder.git.util import (
format_git_branch,
format_git_tag
Expand All @@ -20,7 +21,7 @@ class Defaults(object):
:ivar Optional[str] commit: Default commit sha-1
:ivar str remote: Default remote name
:ivar str source: Default source name
:ivar str protocol: Default git protocol
:ivar GitProtocol protocol: Default git protocol
:ivar int depth: Default depth
:ivar bool recursive: Default recursive value
:ivar str timestamp_author: Default timestamp author
Expand All @@ -33,7 +34,7 @@ def __init__(self, defaults: dict):
:param dict defaults: Parsed YAML python object for defaults
"""

self.protocol = defaults["protocol"]
self.protocol = GitProtocol(defaults["protocol"])
self.source = defaults["source"]
self.remote = defaults.get("remote", "origin")
self.depth = defaults.get("depth", 0)
Expand Down Expand Up @@ -66,7 +67,7 @@ def get_yaml(self) -> dict:
'remote': self.remote,
'source': self.source,
'depth': self.depth,
'protocol': self.protocol}
'protocol': self.protocol.value}

if self.branch is not None:
defaults['branch'] = self.branch
Expand Down
4 changes: 2 additions & 2 deletions src/clowder/model/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from termcolor import colored

from clowder import CLOWDER_DIR
from clowder.git.project_repo import ProjectRepo
from clowder.git import ProjectRepo
from clowder.git.util import (
existing_git_repository,
format_git_branch,
Expand Down Expand Up @@ -121,4 +121,4 @@ def status(self) -> str:
def url(self) -> str:
"""Return project url"""

return git_url(self._source.protocol, self._source.url, self.name)
return git_url(self._source.protocol.value, self._source.url, self.name)
8 changes: 3 additions & 5 deletions src/clowder/model/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@

import clowder.util.formatting as fmt
from clowder import CLOWDER_DIR
from clowder.error import ClowderError
from clowder.error import ClowderExit
from clowder.git.project_repo import ProjectRepo
from clowder.git.project_repo_recursive import ProjectRepoRecursive
from clowder.error import ClowderError, ClowderExit
from clowder.git import ProjectRepo, ProjectRepoRecursive
from clowder.git.util import (
existing_git_repository,
format_git_branch,
Expand Down Expand Up @@ -583,4 +581,4 @@ def _run_forall_command(self, command: str, env: dict, ignore_errors: bool, para
def _url(self) -> str:
"""Return project url"""

return git_url(self.source.protocol, self.source.url, self.name)
return git_url(self.source.protocol.value, self.source.url, self.name)
7 changes: 5 additions & 2 deletions src/clowder/model/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"""

from clowder.git import GitProtocol

from .defaults import Defaults


Expand All @@ -13,6 +15,7 @@ class Source(object):
:ivar str name: Source name
:ivar str url: Source url
:ivar GitProtocol protocol Git protocol
"""

def __init__(self, source: dict, defaults: Defaults):
Expand All @@ -24,7 +27,7 @@ def __init__(self, source: dict, defaults: Defaults):

self.name = source['name']
self.url = source['url']
self.protocol = source.get('protocol', defaults.protocol)
self.protocol = GitProtocol(source.get('protocol', defaults.protocol))

def get_yaml(self) -> dict:
"""Return python object representation for saving yaml
Expand All @@ -35,4 +38,4 @@ def get_yaml(self) -> dict:

return {'name': self.name,
'url': self.url,
'protocol': self.protocol}
'protocol': self.protocol.value}
6 changes: 1 addition & 5 deletions test/unittests/test_git_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import sys
import unittest

from clowder.git.repo import GitRepo
from clowder.git.util import (
ref_type,
truncate_ref
)
from clowder.git import GitRepo, ref_type, truncate_ref


class GitUtilitiesTest(unittest.TestCase):
Expand Down

0 comments on commit 8f8d2e4

Please sign in to comment.