forked from UiPath/uipath-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_pull.py
More file actions
90 lines (70 loc) · 2.49 KB
/
Copy pathcli_pull.py
File metadata and controls
90 lines (70 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""CLI command for pulling remote project files from UiPath StudioWeb solution."""
import asyncio
from pathlib import Path
import click
from uipath.platform.common import UiPathConfig
from ._telemetry import track_command
from ._utils._common import ensure_coded_agent_project, may_override_files
from ._utils._console import ConsoleLogger
from ._utils._project_files import (
ProjectPullError,
pull_project,
)
from ._utils._studio_project import StudioClient
from .middlewares import Middlewares
console = ConsoleLogger()
@click.command()
@click.argument(
"root",
type=click.Path(exists=False, file_okay=False, dir_okay=True, path_type=Path),
default=Path("."),
metavar="",
)
@click.option(
"--overwrite",
is_flag=True,
help="Automatically overwrite local files without prompts",
)
@track_command("pull")
def pull(root: Path, overwrite: bool) -> None:
"""Pull remote project files from Studio Web.
This command pulls the remote project files from a UiPath Studio Web project.
**Environment Variables:**
UIPATH_PROJECT_ID: Required. The ID of the UiPath Studio Web project
**Example:**
$ uipath pull
$ uipath pull /path/to/project
$ uipath pull --overwrite
"""
project_id = UiPathConfig.project_id
if not project_id:
console.error("UIPATH_PROJECT_ID environment variable not found.")
return
studio_client = StudioClient(project_id=project_id)
result = Middlewares.next("pull", studio_client, root, overwrite)
if result.error_message:
console.error(result.error_message)
return
if not result.should_continue:
return
asyncio.run(ensure_coded_agent_project(studio_client))
if not overwrite:
may_override = asyncio.run(may_override_files(studio_client, "local"))
if not may_override:
console.info("Operation aborted.")
return
download_configuration: dict[str | None, Path] = {
None: root,
}
console.log("Pulling UiPath project from Studio Web...")
try:
async def run_pull():
async for update in pull_project(
project_id, download_configuration, studio_client
):
console.info(f"Processing: {update.file_path}")
console.info(update.message)
asyncio.run(run_pull())
console.success("Project pulled successfully")
except ProjectPullError as e:
console.error(f"Failed to pull UiPath project: {str(e)}")