def compare_actual_folder_with_tree(self, root: path, tree: Tree):
     root_name = tree.root
     root_path = root.joinpath(root_name)
     print(root_path)
     self.assertTrue(root_path.exists(), "The path {} should exist, but doesn't".format(root_path))
     children = tree.children(root_name)
     for children in children:
         subtree = tree.subtree(children.identifier)
         self.compare_actual_folder_with_tree(root_path, subtree)
def create_interpret_folder_if_necessary(interpret: str, target_music_folder: path, ask_before_copy: bool) -> path:
    target_interpret_folder = target_music_folder.joinpath(interpret)
    if target_interpret_folder.exists():
        print("The following Interpret folder will be used: {}".format(target_interpret_folder))
    else:
        print("The following Interpret folder will be created: {}".format(target_interpret_folder))
        if (ask_before_copy and click.confirm('Are you okay with this?')) or not ask_before_copy:
            target_interpret_folder.mkdir()
    return target_interpret_folder
def create_dummy_download_folder(root: path, tree: Tree) -> path:
    root_name = tree.root
    root_path = root.joinpath(root_name)

    if not root_path.exists():
        print("Creating {}".format(root_path))
        if root_name.endswith(".mp3"):
            root_path.touch()
        else:
            root_path.mkdir()
        time.sleep(0.01)  # sleep to ensure that the created folders don't have the same ctime

    children = tree.children(root_name)
    for children in children:
        subtree = tree.subtree(children.identifier)
        create_dummy_download_folder(root_path, subtree)
    return root_path
def integrate(source_download_folder: path, target_music_folder: path, ask_before_copy: bool):
    if not target_music_folder.exists():
        raise IntegrationError("The target folder '{}' doesn't exist.".format(target_music_folder))
    latest_folder = source_download_folder.joinpath(get_latest_folder(source_download_folder))
    print("Analyzing latest file {}".format(latest_folder))
    if len(latest_folder.listdir()) == 0:
        raise IntegrationError("The latest folder '{}' has no child folder.".format(latest_folder))
    downloads_album_folder = latest_folder.listdir()[0]
    album = album_parser.parse(downloads_album_folder.basename(), "-")
    print("Parsed album folder name {}. Result: {}".format(downloads_album_folder.basename(), album))
    target_interpret_folder = create_interpret_folder_if_necessary(album.interpret, target_music_folder, ask_before_copy)

    wanted_target_album_folder = target_interpret_folder.joinpath(album.name)
    if wanted_target_album_folder.exists():
        raise IntegrationError("The target album folder {} already exists.".format(wanted_target_album_folder))
    print("I'm going to copy \n\t{} \n\tto \n\t{}".format(downloads_album_folder, wanted_target_album_folder))
    if (ask_before_copy and click.confirm('Are you okay with this?')) or not ask_before_copy:
        downloads_album_folder.copytree(wanted_target_album_folder)
        click.echo("Copied successfully")
        print("Cleanup: Removing old folder in downloads folder: {}".format(latest_folder))
        latest_folder.rmtree()
        return wanted_target_album_folder
Esempio n. 5
0
#
# carefree-objects is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with carefree-objects.  If not, see <http://www.gnu.org/licenses/>.

"""libcarefree_objects

.. moduleauthor:: Stefan Zimmermann <*****@*****.**>
"""
__all__ = 'PREFIX', 'INCLUDE_PATH', 'LIB_PATH',

from path import path as Path

from .libcfo import __version__, __requires__


# Determine the location prefix of libcarefree_object's data_files
PREFIX = Path(__path__[0])
with PREFIX:
    if Path('PREFIX').exists():
        with Path('PREFIX').open() as f:
            PREFIX = Path(f.read().strip())

INCLUDE_PATH = PREFIX.joinpath('include')

LIB_PATH = PREFIX.joinpath('lib')
def get_latest_folder(dir_path: path) -> str:
    files = [file for file in dir_path.listdir()]
    files.sort(key=lambda file: dir_path.joinpath(file).getctime(), reverse=True)
    return files[0]