예제 #1
0
def copytree(src, dest, test=False):
    """recursively copies a directory tree"""
    import shutil

    try:
        shutil.copytree(src, dest)
    except PermissionError:
        import os
        import stat
        os.chmod(src, stat.S_IRWXU)

        if os.path.exists(dest):
            # removes files from half-done copytree
            from src.praxxis.util import rmtree
            rmtree.rmtree(dest, test=True)

        if not os.path.exists(dest):
            try:
                shutil.copytree(src, dest)
            except Exception as e:
                if test and "WinError" in str(e):
                    # exits pytest
                    import pytest
                    from src.praxxis.display import display_error
                    message = display_error.pytest_windows_permissions_error(
                        str(e))
                    pytest.exit(message)
                else:
                    raise e
예제 #2
0
def test_init_output(setup, output_root):
    from src.praxxis.util import rmtree
    import os 

    assert os.path.exists(output_root)
    rmtree.rmtree(output_root, test=True)
    assert not os.path.exists(output_root)

    entry_notebook.init_output(output_root)

    assert os.path.exists(output_root)
예제 #3
0
def test_init_library(setup, library_root, library_db):
    from src.praxxis.util import rmtree
    import os 
    
    assert os.path.exists(library_root)
    assert os.path.exists(library_db)
    rmtree.rmtree(library_root, test=True)
    assert not os.path.exists(library_root)
    
    entry_library.init_library(library_root, library_db)
    
    assert os.path.exists(library_root)
    assert os.path.exists(library_db)
예제 #4
0
def test_init_scene(setup, scene_root, history_db, default_scene_name):
    from src.praxxis.util import rmtree
    import os

    assert os.path.exists(scene_root)
    assert os.path.exists(history_db)
    rmtree.rmtree(scene_root, test=True)
    os.remove(history_db)
    assert not os.path.exists(scene_root)

    entry_scene.init_scene(scene_root, history_db, default_scene_name)

    assert os.path.exists(scene_root)
예제 #5
0
def test_init_rulesengine(setup, rulesengine_root, rulesengine_db):
    from src.praxxis.util import rmtree
    import os 

    assert os.path.exists(rulesengine_root)
    assert os.path.exists(rulesengine_db)
    os.remove(rulesengine_db)
    rmtree.rmtree(rulesengine_root, test=True)
    assert not os.path.exists(rulesengine_root)
    assert not os.path.exists(rulesengine_db)

    entry_rulesengine.init_rulesengine(rulesengine_root, rulesengine_db)

    assert os.path.exists(rulesengine_root)
    assert os.path.exists(rulesengine_db)
예제 #6
0
def test_add_git_library(setup, library_db, git_root, query_start, query_end):
    from src.praxxis.library import add_library
    from src.praxxis.library import remove_library
    from src.praxxis.library import list_library
    from tests.src.praxxis.util import dummy_object
    from src.praxxis.util import rmtree

    url = dummy_object.make_dummy_git_repo()
    add_library.add_library(url, library_db, git_root)

    libraries = list_library.list_library(library_db, query_start, query_end)
    assert len(libraries) == 1
    remove_library.remove_library(url, library_db, query_start, query_end)
    libraries = list_library.list_library(library_db, query_start, query_end)

    assert len(libraries) == 0
    rmtree.rmtree(git_root, test=True)
예제 #7
0
def test_init(setup, init_root, library_root, library_db, output_root, scene_root, history_db, telemetry_db, rulesengine_root, rulesengine_db, model_root, model_db, default_scene_name):
    pass
    from src.praxxis.util import rmtree
    import os 
    
    assert os.path.exists(init_root)
    rmtree.rmtree(init_root, test=True)
    assert not os.path.exists(init_root)
    roots.init(init_root, library_root, library_db, output_root, scene_root, history_db, telemetry_db, rulesengine_root, rulesengine_db, model_root, model_db, default_scene_name, False)
    
    assert os.path.exists(init_root)
    assert os.path.exists(library_root)
    assert os.path.exists(library_db)
    assert os.path.exists(output_root)
    assert os.path.exists(scene_root)
    assert os.path.exists(history_db)
    assert os.path.exists(telemetry_db)
예제 #8
0
def delete_scene(args, scene_root, history_db):
    """deletes a specified scene, including all its data"""
    import shutil
    import os

    from src.praxxis.scene import current_scene
    from src.praxxis.sqlite import sqlite_scene
    from src.praxxis.display import display_scene
    from src.praxxis.util import error
    from src.praxxis.scene import scene

    if hasattr(args, "name"):
        if(args.name is None):
            name = sqlite_scene.get_current_scene(history_db)
        else:
            name = args.name
    else:
        name = args

    try:
        tmp_name = scene.get_scene_by_ordinal(args, name, history_db)
    except error.SceneNotFoundError as e:
        raise e
    except error.EndEndedSceneError as e:
        pass
        
    if tmp_name is not None:
        name = tmp_name

    directory = os.path.join(scene_root, name)

    if os.path.exists(directory):
        from src.praxxis.util import rmtree
        try:
            sqlite_scene.delete_scene(history_db, name)
            rmtree.rmtree(directory)
            display_scene.display_delete_scene_success(name)
            return name
        except error.LastActiveSceneError as e:
            raise e
    else:
        raise error.SceneNotFoundError(name)
예제 #9
0
def add_library(args, library_db, git_root):
    """adds a library from git or path"""
    from src.praxxis.util import error
    from src.praxxis.display import display_error
    from src.praxxis.display import display_library
    from src.praxxis.library import sync_library
    import giturlparse
    import os

    path = args.path

    remote = giturlparse.parse(path)

    if not remote.valid:
        # if it is not a valid github remote

        if os.path.exists(path):
            # check if the path exists and is a directory
            if os.path.isdir(path):
                sync_library.sync_library(os.path.abspath(path),
                                          library_db,
                                          custom_path=True)
            else:
                raise error.NotDirectoryError(path)
        else:
            raise error.LibraryNotFoundError(path)
    else:
        # if the path is a valid git remote
        from src.praxxis.util import rmtree
        from git import Repo
        import sys
        import subprocess

        if not os.path.exists(git_root):
            # check if the git root exists, and if it doesn't, make it here
            os.mkdir(git_root)
            display_library.display_init_git_library(git_root)

        repo_author = remote.data["owner"]
        repo_name = remote.data["repo"]
        repo_root = os.path.join(git_root, repo_author, repo_name)

        if os.path.exists(repo_root):
            # if the path exits, remove it and clone again
            rmtree.rmtree(repo_root)
            display_error.repo_exists_warning()

        try:
            # git clone the repo
            subprocess.call(["git", "clone", path, repo_root])
        except KeyboardInterrupt:
            # if it is interrupted, delete the empty directory that git creates
            repo_author_root = os.path.join(git_root, repo_author)
            if len(os.listdir(repo_author_root)) == 0:
                os.rmdir(repo_author_root)
            sys.exit(0)

        remote_https = giturlparse.parse(path).url2https
        repo_root_abspath = os.path.abspath(repo_root)
        sync_library.sync_library(repo_root_abspath,
                                  library_db,
                                  custom_library_name="%s_%s" %
                                  (repo_author, repo_name),
                                  custom_path=True,
                                  remote=path,
                                  remote_origin=remote_https)