Skip to content

Commit

Permalink
Finished _setup_directories refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Florath <[email protected]>
  • Loading branch information
florath committed May 6, 2017
1 parent 34af0b7 commit b80bec2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 35 deletions.
19 changes: 11 additions & 8 deletions rmtoo/lib/vcs/FileInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ class FileInterface(Interface):
def __init__(self, config):
Interface.__init__(self, config)

@staticmethod
def _abs_path(directory):
'''Convert the given directory path into an absolute path.'''
if not os.path.isabs(directory):
return os.path.abspath(directory)
# This is overloaded and therefore must be a normal method.
# pylint: disable=no-self-use
def _adapt_dir_path(self, directory):
return directory

# This is overloaded and therefore must be a normal method.
# pylint: disable=no-self-use
def _adapt_ext_path(self, directory):
return directory

# pylint: disable=no-self-use,unused-argument
Expand All @@ -50,13 +53,13 @@ def _setup_directories(self, cfg):
tracer.info("Directory [%s] not configured - skipping.",
dir_type)
continue
dirs = list(map(self._abs_path, config_dirs))
dirs = list(map(self._adapt_dir_path, config_dirs))
self._check_list_of_strings(dir_type, dirs)

new_directories = []
for directory in config_dirs:
for directory in dirs:
self._extended_directory_check(directory)
new_directories.append(directory)
new_directories.append(self._adapt_ext_path(directory))
all_dirs[dir_type] = new_directories

for dir_type, directory in iteritems(all_dirs):
Expand Down
37 changes: 10 additions & 27 deletions rmtoo/lib/vcs/Git.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
class Git(FileInterface):
'''Handles a git repository.'''

# This is overloaded and therefore must be a normal method.
# pylint: disable=no-self-use
def _adapt_dir_path(self, directory):
'''Convert the given directory path into an absolute path.'''
if not os.path.isabs(directory):
return os.path.abspath(directory)
return directory

def _extended_directory_check(self, directory):
'''Checks if all the directories are the in repository.
The absolute path is computed if the path is relative and
Expand All @@ -40,36 +48,12 @@ def _extended_directory_check(self, directory):
% directory)
return

def __cut_off_repo_dir(self, directory):
def _adapt_ext_path(self, directory):
'''Cuts off the repository directory from the directory.'''
# +1: cut off the '/' also.
len_repo_base_dir = len(self.__repo_base_dir) + 1
return directory[len_repo_base_dir:]


def MY_setup_directories(self, cfg):
'''Cleans up and unifies the directories.'''
tracer.debug("called")
# TODO: duplicated code - also in FileSystem
for dir_type in ["requirements", "topics", "constraints", "testcases"]:
config_dirs = cfg.get_rvalue_default(dir_type + "_dirs", None)
if config_dirs is None:
tracer.info("Directory [%s] not configured - skipping." %
dir_type)
continue
dirs = list(map(self._abs_path, config_dirs))
self._check_list_of_strings(dir_type, dirs)

new_directories = []
for directory in dirs:
self._extended_directory_check(directory)
new_directories.append(self.__cut_off_repo_dir(directory))
self.__dirs[dir_type] = new_directories

for dir_type, directory in iteritems(self.__dirs):
tracer.debug("[%s] directories [%s]" % (dir_type, directory))


def __setup_repo(self, directory):
'''Sets up the repository.'''
tracer.debug("called")
Expand Down Expand Up @@ -115,8 +99,7 @@ def __init__(self, config):
self.__dirs = {}
self.__repo_base_dir = None
self.__repo = None
self.__dirs = {}
self.MY_setup_directories(cfg)
self.__dirs = self._setup_directories(cfg)

def get_commits(self):
'''Return an iterator for all the commits.'''
Expand Down

0 comments on commit b80bec2

Please sign in to comment.