Ejemplo n.º 1
0
def deploy_directory(path):
    """
    machaonディレクトリを配備する。
    Params:
        path(Path): 配備先のディレクトリ
    """
    machaon = path / "machaon"
    packages = machaon / "packages"
    credentials = machaon / "credential"
    store = machaon / "store"
    local = machaon / "local"

    # ディレクトリの作成
    for p in (packages, credentials, store, local):
        p.makedirs()

    # 空ファイルの配置
    configs = Path(__file__).dir() / "configs"
    machaon.copy_from(configs / "readme.txt")
    machaon.copy_from(configs / "apps.ini")
    credentials.copy_from(configs / "credential.ini")

    # スタートアップスクリプトの配置
    if is_osx():
        main = path.copy_from(configs / "main.py")
        # main.pyのパスを書き込んだ立ち上げスクリプトを生成
        deploy_osx_start_command(main)

    elif is_windows():
        path.copy_from(configs / "main.py")
Ejemplo n.º 2
0
def deploy_osx_start_command(main):
    from machaon.types.file import TextFile
    starter = main.with_name("start.command")
    configs = Path(__file__).dir() / "configs"
    starter_template = TextFile(configs / "osx" / "start.command").text()
    with TextFile(starter, encoding="utf-8").write_stream() as fo:
        fo.write(starter_template.format(main))
    # 実行権限を与える
    os.chmod(starter.get(), 0o755)
    return starter
Ejemplo n.º 3
0
 def trans_deploy(self, app, path):
     ''' @task
     machaonディレクトリを移譲する。
     Params:
         path(Path): 新たにmachaonが配備されるディレクトリ
     '''
     from machaon.types.shell import Path
     from machaon.app import transfer_deployed_directory
     transfer_deployed_directory(app,
                                 Path(self.context.root.get_basic_dir()),
                                 path)
Ejemplo n.º 4
0
def test_deploy(tmpdir):
    deploydir = tmpdir.mkdir("deploy")
    deploy_directory(Path(deploydir))

    assert deploydir.join("machaon").check()
    assert deploydir.join("machaon", "store").check()
    assert deploydir.join("machaon", "packages").check()
    assert deploydir.join("machaon", "credential").check()
    assert deploydir.join("machaon", "credential", "credential.ini").check()
    assert deploydir.join("machaon", "local").check()
    assert deploydir.join("machaon", "apps.ini").check()
    assert deploydir.join("main.py").check()

    deploydir2 = tmpdir.mkdir("deploy2")
    spi = TempSpirit()
    transfer_deployed_directory(spi, Path(deploydir.join("machaon")), Path(deploydir2))

    assert deploydir2.join("machaon").check()
    assert deploydir2.join("machaon", "apps.ini").check()
    assert deploydir2.join("machaon", "credential", "credential.ini").check()
    assert deploydir2.join("main.py").check()

    assert not deploydir.join("machaon").check()
Ejemplo n.º 5
0
 def save(self, app):
     """ @task
     ファイルをセーブする。
     """
     # パスを変えて何度か試行する
     savepath = self.pathstr
     for retry_level in range(1, 4):
         try:
             self.savefile(savepath)
         except PermissionError:
             savepath = self._path.with_basename_format("{}_{}", retry_level).get()
         else: # 正常終了
             break
     else:
         app.post("error", '"{}"に保存できません。別のアプリで開かれています。'.format(savepath))
     self._path = Path(savepath)
Ejemplo n.º 6
0
def test_path_concatenate():
    a = Path("desktop/folder")
    b = Path("subfolder/file.txt")
    c = a / b
    assert c.path() == os.path.join(a.path(), b.path())
Ejemplo n.º 7
0
 def path(self, p):
     """ ファイルパス操作オブジェクト """
     from machaon.types.shell import Path
     return Path(p)
Ejemplo n.º 8
0
 def __init__(self, path=None):
     self._path = path or Path()
     self._file = None