# Path: ddsc/core/util.py
# class KindType(object):
#     """
#     The types of items that are part of a project. Strings are from the duke-data-service.
#     """
#     file_str = 'dds-file'
#     folder_str = 'dds-folder'
#     project_str = 'dds-project'
# 
#     @staticmethod
#     def is_file(item):
#         return item.kind == KindType.file_str
# 
#     @staticmethod
#     def is_folder(item):
#         return item.kind == KindType.folder_str
# 
#     @staticmethod
#     def is_project(item):
#         return item.kind == KindType.project_str
# 
# Path: ddsc/exceptions.py
# class DDSUserException(Exception):
#     """
#     Exception with an error message to be displayed to the user on the command line.
#     """
#     pass


import os
from ddsc.core.util import KindType
from ddsc.exceptions import DDSUserException
        self.project = project
        self.source_remote_path = source_remote_path
        self.target_remote_path = target_remote_path

    def run(self):
        source = self.project.get_child_for_path(self.source_remote_path)
        new_parent = self.get_new_parent()
        new_name = self.get_new_name()
        if new_parent:
            source = source.change_parent(new_parent)
        if new_name:
            source = source.rename(new_name)
        return source

    def get_new_parent(self):
        target = self.project.try_get_item_for_path(self.target_remote_path)
        if target:
            if self.is_folder_or_project(target):
                return target
            else:
                raise DDSUserException("Cannot move to existing file {}.".format(self.target_remote_path))
        else:
            source_parent_remote_path = os.path.dirname(self.source_remote_path)
            target_parent_remote_path = os.path.dirname(self.target_remote_path)
            if source_parent_remote_path != target_parent_remote_path:
                target_parent = self.project.try_get_item_for_path(target_parent_remote_path)
                if target_parent:
                    if self.is_folder_or_project(target_parent):
                        return target_parent
                    else:

# Path: ddsc/core/util.py
# class KindType(object):
#     """
#     The types of items that are part of a project. Strings are from the duke-data-service.
#     """
#     file_str = 'dds-file'
#     folder_str = 'dds-folder'
#     project_str = 'dds-project'
# 
#     @staticmethod
#     def is_file(item):
#         return item.kind == KindType.file_str
# 
#     @staticmethod
#     def is_folder(item):
#         return item.kind == KindType.folder_str
# 
#     @staticmethod
#     def is_project(item):
#         return item.kind == KindType.project_str
# 
# Path: ddsc/exceptions.py
# class DDSUserException(Exception):
#     """
#     Exception with an error message to be displayed to the user on the command line.
#     """
#     pass


# Path: ddsc/core/moveutil.py
import os
from ddsc.core.util import KindType
from ddsc.exceptions import DDSUserException

        self.project = project
        self.source_remote_path = source_remote_path
        self.target_remote_path = target_remote_path

    def run(self):
        source = self.project.get_child_for_path(self.source_remote_path)
        new_parent = self.get_new_parent()
        new_name = self.get_new_name()
        if new_parent:
            source = source.change_parent(new_parent)
        if new_name:
            source = source.rename(new_name)
        return source

    def get_new_parent(self):
        target = self.project.try_get_item_for_path(self.target_remote_path)
        if target:
            if self.is_folder_or_project(target):
                return target
            else:
                raise DDSUserException("Cannot move to existing file {}.".format(self.target_remote_path))
        else:
            source_parent_remote_path = os.path.dirname(self.source_remote_path)
            target_parent_remote_path = os.path.dirname(self.target_remote_path)
            if source_parent_remote_path != target_parent_remote_path:
                target_parent = self.project.try_get_item_for_path(target_parent_remote_path)
                if target_parent:
                    if self.is_folder_or_project(target_parent):
                        return target_parent
                    else:

                        raise DDSUserException("Target parent {} is a file.".format(target_parent_remote_path))