unknown-cli 0.3.1__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {unknown-cli-0.3.1 → unknown-cli-0.4.0}/PKG-INFO +1 -1
- {unknown-cli-0.3.1 → unknown-cli-0.4.0}/unknown_cli.egg-info/PKG-INFO +1 -1
- {unknown-cli-0.3.1 → unknown-cli-0.4.0}/unknown_cli.egg-info/SOURCES.txt +1 -0
- unknown-cli-0.4.0/unknowncli/VERSION +1 -0
- {unknown-cli-0.3.1 → unknown-cli-0.4.0}/unknowncli/__main__.py +2 -0
- unknown-cli-0.4.0/unknowncli/commands/stream.py +347 -0
- unknown-cli-0.3.1/unknowncli/VERSION +0 -1
- {unknown-cli-0.3.1 → unknown-cli-0.4.0}/README.md +0 -0
- {unknown-cli-0.3.1 → unknown-cli-0.4.0}/setup.cfg +0 -0
- {unknown-cli-0.3.1 → unknown-cli-0.4.0}/setup.py +0 -0
- {unknown-cli-0.3.1 → unknown-cli-0.4.0}/unknown_cli.egg-info/dependency_links.txt +0 -0
- {unknown-cli-0.3.1 → unknown-cli-0.4.0}/unknown_cli.egg-info/entry_points.txt +0 -0
- {unknown-cli-0.3.1 → unknown-cli-0.4.0}/unknown_cli.egg-info/requires.txt +0 -0
- {unknown-cli-0.3.1 → unknown-cli-0.4.0}/unknown_cli.egg-info/top_level.txt +0 -0
- {unknown-cli-0.3.1 → unknown-cli-0.4.0}/unknowncli/__init__.py +0 -0
- {unknown-cli-0.3.1 → unknown-cli-0.4.0}/unknowncli/commands/__init__.py +0 -0
- {unknown-cli-0.3.1 → unknown-cli-0.4.0}/unknowncli/commands/project.py +0 -0
- {unknown-cli-0.3.1 → unknown-cli-0.4.0}/unknowncli/data/.p4ignore.txt +0 -0
- {unknown-cli-0.3.1 → unknown-cli-0.4.0}/unknowncli/utils.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.4.0
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
import time
|
|
3
|
+
import sys, os
|
|
4
|
+
import requests
|
|
5
|
+
import logging
|
|
6
|
+
import socket
|
|
7
|
+
from tabulate import tabulate
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from pprint import pprint
|
|
10
|
+
from ..utils import dumps, abort, get_datafile
|
|
11
|
+
from subprocess import check_call, call
|
|
12
|
+
from P4 import P4, P4Exception
|
|
13
|
+
import shutil
|
|
14
|
+
|
|
15
|
+
log = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
from typer import Context, launch, echo, secho, Option, Typer, confirm, prompt, style, progressbar
|
|
18
|
+
|
|
19
|
+
app = Typer()
|
|
20
|
+
task_app = Typer(name="task")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
hostname = socket.gethostname().lower()
|
|
24
|
+
SUBST_DRIVE = "S:"
|
|
25
|
+
path = f"{SUBST_DRIVE}\\sn2-main\\"
|
|
26
|
+
BASE_STREAM = "//Project/SN2-Main"
|
|
27
|
+
UE_STREAM = "//project/sn2-main-ue"
|
|
28
|
+
|
|
29
|
+
p4 = None
|
|
30
|
+
|
|
31
|
+
def connect_p4():
|
|
32
|
+
p4_conn = P4()
|
|
33
|
+
try:
|
|
34
|
+
p4_conn.connect()
|
|
35
|
+
except Exception as e:
|
|
36
|
+
abort(f"Cannot establish connection with Perforce server: {e}...")
|
|
37
|
+
return p4_conn
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@task_app.callback()
|
|
41
|
+
def main():
|
|
42
|
+
"""
|
|
43
|
+
Manage task streams.
|
|
44
|
+
|
|
45
|
+
This tool is highly opinionated and expects you to be using the //Project/SN2-Main-UE stream and be working in a workspace called <username>_<label>_sn2-main
|
|
46
|
+
"""
|
|
47
|
+
global p4
|
|
48
|
+
p4 = connect_p4()
|
|
49
|
+
ret = get_current_stream()
|
|
50
|
+
client = get_current_client()
|
|
51
|
+
|
|
52
|
+
if "Stream" not in ret:
|
|
53
|
+
abort("Invalid workspace. You must be working in Streams to use this tool")
|
|
54
|
+
stream_name = ret["Stream"]
|
|
55
|
+
parent = ret["Parent"]
|
|
56
|
+
secho(f"You are currently working in client {client['Client']} - stream: {stream_name}, root: {client['Root']}", fg="blue")
|
|
57
|
+
if parent.lower() != UE_STREAM and stream_name.lower() != UE_STREAM:
|
|
58
|
+
abort(f"To use this tool you must be working in the {UE_STREAM} stream while your workspace is set on {stream_name}. Please change your workspace with 'p4 set P4CLIENT <username>_<label>_sn2-main'")
|
|
59
|
+
|
|
60
|
+
def get_task_streams():
|
|
61
|
+
lst = p4.run_streams("-F", f"Owner=jonb Type=task baseParent={BASE_STREAM}")
|
|
62
|
+
return lst
|
|
63
|
+
|
|
64
|
+
def get_current_stream():
|
|
65
|
+
ret = p4.run_stream("-o")[0]
|
|
66
|
+
return ret
|
|
67
|
+
|
|
68
|
+
def get_current_client():
|
|
69
|
+
ret = p4.run_client("-o")[0]
|
|
70
|
+
return ret
|
|
71
|
+
|
|
72
|
+
def get_clients():
|
|
73
|
+
try:
|
|
74
|
+
specs = p4.run_clients("-u", p4.user)
|
|
75
|
+
except Exception as e:
|
|
76
|
+
abort(str(e))
|
|
77
|
+
ret = {}
|
|
78
|
+
for s in specs:
|
|
79
|
+
host = s["Host"].lower()
|
|
80
|
+
if host == hostname or not host:
|
|
81
|
+
ret[s["Stream"].lower()] = s
|
|
82
|
+
return ret
|
|
83
|
+
|
|
84
|
+
def sync():
|
|
85
|
+
s = confirm("Sync latest?")
|
|
86
|
+
|
|
87
|
+
if not s:
|
|
88
|
+
return
|
|
89
|
+
|
|
90
|
+
secho(f"Syncing all (this will take a while)...")
|
|
91
|
+
try:
|
|
92
|
+
ret = p4.run_sync("-q", f"{path}...")
|
|
93
|
+
except P4Exception as e:
|
|
94
|
+
print(e)
|
|
95
|
+
|
|
96
|
+
@task_app.command()
|
|
97
|
+
def create(label: str = Option(None, prompt="Task branch label")):
|
|
98
|
+
"""
|
|
99
|
+
Create a new task branch
|
|
100
|
+
"""
|
|
101
|
+
if not label:
|
|
102
|
+
abort("Aborted.")
|
|
103
|
+
clients = get_clients()
|
|
104
|
+
|
|
105
|
+
ue_stream_client = None
|
|
106
|
+
for k, c in clients.items():
|
|
107
|
+
if k == UE_STREAM:
|
|
108
|
+
ue_stream_client = c
|
|
109
|
+
if not ue_stream_client:
|
|
110
|
+
abort(f"You have no workspace mapped to the {UE_STREAM} stream. Please set one up.")
|
|
111
|
+
print(ue_stream_client)
|
|
112
|
+
task_client_name = ue_stream_client["client"] + "_task"
|
|
113
|
+
task_client = None
|
|
114
|
+
for k, c in clients.items():
|
|
115
|
+
if c["client"] == task_client_name:
|
|
116
|
+
echo(f"Reusing existing task workspace {k}")
|
|
117
|
+
task_client = c
|
|
118
|
+
break
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
d = datetime.datetime.utcnow().isoformat().split("T")[0]
|
|
122
|
+
label = label.replace(" ", "_").lower()
|
|
123
|
+
stream_name = f"{p4.user}-{d}-{label}"
|
|
124
|
+
full_stream_name = f"//Project/{stream_name}"
|
|
125
|
+
secho(f"Creating task stream {stream_name} from {UE_STREAM}...")
|
|
126
|
+
args = f"""
|
|
127
|
+
Stream: {full_stream_name}
|
|
128
|
+
Owner: {p4.user}
|
|
129
|
+
Name: {stream_name}
|
|
130
|
+
Parent: {UE_STREAM}
|
|
131
|
+
Type: task
|
|
132
|
+
Description:
|
|
133
|
+
Created by {p4.user}.
|
|
134
|
+
Options: allsubmit unlocked toparent fromparent mergedown
|
|
135
|
+
ParentView: inherit
|
|
136
|
+
Paths:
|
|
137
|
+
share ...
|
|
138
|
+
"""
|
|
139
|
+
p4.input = args
|
|
140
|
+
ret = p4.run_stream("-i", "-t", "task")
|
|
141
|
+
print(ret[0])
|
|
142
|
+
|
|
143
|
+
secho(f"Populating stream {full_stream_name}...")
|
|
144
|
+
try:
|
|
145
|
+
ret = p4.run_populate("-o", "-S", full_stream_name, "-r", "-d", "Initial branch")
|
|
146
|
+
except P4Exception as e:
|
|
147
|
+
if e.errors:
|
|
148
|
+
secho(e.errors[0], fg="yellow")
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
if not task_client and 0:
|
|
152
|
+
root = f"{ue_stream_client['Root']}_task"
|
|
153
|
+
echo("Creating new workspace {task_client_name} -> {root}...")
|
|
154
|
+
client_spec = f"""
|
|
155
|
+
Client: {task_client_name}
|
|
156
|
+
Owner: {ue_stream_client['Owner']}
|
|
157
|
+
Host: {ue_stream_client['Host']}
|
|
158
|
+
Description:
|
|
159
|
+
Automatically created task workspace for {ue_stream_client['Owner']}
|
|
160
|
+
|
|
161
|
+
Root: {root}
|
|
162
|
+
Options: noallwrite noclobber nocompress unlocked nomodtime normdir
|
|
163
|
+
SubmitOptions: submitunchanged
|
|
164
|
+
LineEnd: local
|
|
165
|
+
Stream: {full_stream_name}"""
|
|
166
|
+
p4.input = client_spec
|
|
167
|
+
p4.run_client("-i")
|
|
168
|
+
|
|
169
|
+
p4.client = task_client_name
|
|
170
|
+
secho(f"Switching current workspace to {full_stream_name}...")
|
|
171
|
+
p4.run_client("-s", "-S", full_stream_name)
|
|
172
|
+
ret = p4.run_client("-o")[0]
|
|
173
|
+
root_path = ret["Root"]
|
|
174
|
+
|
|
175
|
+
# if not task_client:
|
|
176
|
+
# secho("Force syncing your new workspace folder to latest")
|
|
177
|
+
# ret = p4.run_sync(f"{root}...#head")
|
|
178
|
+
# else:
|
|
179
|
+
# sync()
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
ret = p4.run_stream("-o")[0]
|
|
183
|
+
stream_name = ret["Stream"]
|
|
184
|
+
parent = ret["Parent"]
|
|
185
|
+
|
|
186
|
+
if ret["Type"] != "task":
|
|
187
|
+
abort(f"Something went wrong. Current stream {stream_name} is not a task stream")
|
|
188
|
+
|
|
189
|
+
secho(f"You are now working in task stream {stream_name} from parent {parent}", bold=True, fg="green")
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
@task_app.command()
|
|
193
|
+
def switch():
|
|
194
|
+
"""
|
|
195
|
+
Lists your current task streams and lets you switch between them
|
|
196
|
+
"""
|
|
197
|
+
task_streams = get_task_streams()
|
|
198
|
+
stream = get_current_stream()
|
|
199
|
+
parent = None
|
|
200
|
+
if stream["Type"] == "task":
|
|
201
|
+
parent = stream["Parent"]
|
|
202
|
+
for i, t in enumerate(task_streams):
|
|
203
|
+
secho(f"{i+1} : {t['Stream']}")
|
|
204
|
+
if parent:
|
|
205
|
+
secho(f"0 : {parent}")
|
|
206
|
+
|
|
207
|
+
if not task_streams:
|
|
208
|
+
abort("You have no task streams. You can create one with the 'create' command")
|
|
209
|
+
n = prompt("\nSelect a stream to work in")
|
|
210
|
+
if n is None:
|
|
211
|
+
abort("No stream selected")
|
|
212
|
+
n = int(n)
|
|
213
|
+
if n == 0:
|
|
214
|
+
new_stream = parent
|
|
215
|
+
else:
|
|
216
|
+
new_stream = task_streams[n-1]["Stream"]
|
|
217
|
+
|
|
218
|
+
secho(f"\nSwitching to stream {new_stream}", bold=True)
|
|
219
|
+
try:
|
|
220
|
+
p4.run_client("-s", "-S", new_stream)
|
|
221
|
+
except P4Exception as e:
|
|
222
|
+
abort(e)
|
|
223
|
+
|
|
224
|
+
sync()
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
@task_app.command()
|
|
229
|
+
def update():
|
|
230
|
+
"""
|
|
231
|
+
Merge from parent down to your current task branch
|
|
232
|
+
"""
|
|
233
|
+
ret = p4.run_stream("-o")[0]
|
|
234
|
+
stream_name = ret["Stream"]
|
|
235
|
+
parent = ret["Parent"]
|
|
236
|
+
if ret["Type"] != "task":
|
|
237
|
+
abort(f"Current stream {stream_name} is not a task stream")
|
|
238
|
+
|
|
239
|
+
ret = p4.run_client("-o")[0]
|
|
240
|
+
root_path = ret["Root"]
|
|
241
|
+
client = ret["Client"]
|
|
242
|
+
|
|
243
|
+
ret = p4.run_opened()
|
|
244
|
+
if (len(ret)):
|
|
245
|
+
abort("Your default pending changelist must be empty.")
|
|
246
|
+
|
|
247
|
+
secho(f"Integrating latest from parent {parent} to task stream {stream_name}...", bold=True)
|
|
248
|
+
|
|
249
|
+
p4.input = f"""
|
|
250
|
+
Change: new
|
|
251
|
+
Client: {client}
|
|
252
|
+
User: {p4.user}
|
|
253
|
+
|
|
254
|
+
Description:
|
|
255
|
+
Automatically merge {UE_STREAM} to {stream_name}
|
|
256
|
+
|
|
257
|
+
"""
|
|
258
|
+
|
|
259
|
+
try:
|
|
260
|
+
cmd = ["-Af", "-S", stream_name, "-r", f"{stream_name}/..."]
|
|
261
|
+
ret = p4.run_merge(*cmd)
|
|
262
|
+
except P4Exception as e:
|
|
263
|
+
if e.errors:
|
|
264
|
+
secho(e.errors[0], fg="red")
|
|
265
|
+
if e.warnings:
|
|
266
|
+
secho(e.warnings[0], fg="yellow")
|
|
267
|
+
if "already integrated" in str(e):
|
|
268
|
+
secho(f"Your task stream is already up to date with {UE_STREAM}", fg="green")
|
|
269
|
+
return
|
|
270
|
+
#ret = p4.run_opened()
|
|
271
|
+
#for f in ret:
|
|
272
|
+
ret = p4.run_resolve("-f", "-am", "-as", f"{root_path}/...")
|
|
273
|
+
|
|
274
|
+
# p4 fstat -Olhp -Rco -e default //jonb_work_sn2-main/...
|
|
275
|
+
ret = p4.run_fstat("-Olhp", "-Rco", "-e", "default", f"{root_path}/...")
|
|
276
|
+
if not ret:
|
|
277
|
+
abort("Your task stream is up to date.")
|
|
278
|
+
|
|
279
|
+
unresolved = []
|
|
280
|
+
for r in ret:
|
|
281
|
+
if "unresolved" in r:
|
|
282
|
+
unresolved.append(r)
|
|
283
|
+
secho(f" {r['clientFile']}... conflict", fg="yellow")
|
|
284
|
+
else:
|
|
285
|
+
secho(f" {r['clientFile']}... ok", fg="green")
|
|
286
|
+
|
|
287
|
+
if unresolved:
|
|
288
|
+
y = confirm(f"\nOverwrite conflicting files in your task stream from {UE_STREAM}?")
|
|
289
|
+
if not y:
|
|
290
|
+
abort("Please resolve remaining files in p4v")
|
|
291
|
+
for r in unresolved:
|
|
292
|
+
ret = p4.run_resolve("-f", "-at", f"{r['clientFile']}")
|
|
293
|
+
secho("Unresolved files have been overwritten by parent stream")
|
|
294
|
+
|
|
295
|
+
ret = p4.run_fstat("-Olhp", "-Rco", "-e", "default", f"{root_path}/...")
|
|
296
|
+
filelist = ""
|
|
297
|
+
for r in ret:
|
|
298
|
+
if "unresolved" in r:
|
|
299
|
+
abort("There are still unresolved files in your pending changelist. Please resolve them in p4v")
|
|
300
|
+
filelist += f" {r['depotFile']}\n"
|
|
301
|
+
|
|
302
|
+
mr = ""
|
|
303
|
+
if unresolved:
|
|
304
|
+
mr = f"{len(unresolved)} unresolvable files were overwritten."
|
|
305
|
+
|
|
306
|
+
txt = f"""
|
|
307
|
+
Change: new
|
|
308
|
+
Client: {client}
|
|
309
|
+
User: {p4.user}
|
|
310
|
+
|
|
311
|
+
Description:
|
|
312
|
+
Automatically merge {UE_STREAM} to {stream_name}. {mr}
|
|
313
|
+
Files:
|
|
314
|
+
{filelist}
|
|
315
|
+
"""
|
|
316
|
+
p4.input = txt
|
|
317
|
+
p4.run_submit('-i')
|
|
318
|
+
|
|
319
|
+
ret = p4.run_resolve("-f", "-am", "-as", f"{root_path}...")
|
|
320
|
+
ret = p4.run_fstat("-Olhp", "-Rco", "-e", "default", f"{root_path}/...")
|
|
321
|
+
if not ret:
|
|
322
|
+
secho(f"Your task stream is now up to date with {UE_STREAM}", fg="green")
|
|
323
|
+
else:
|
|
324
|
+
abort("Something is amiss. Your task stream is not up to date after the merge. Take a look at p4v")
|
|
325
|
+
|
|
326
|
+
@task_app.command()
|
|
327
|
+
def delete():
|
|
328
|
+
"""
|
|
329
|
+
Permanently delete your current task stream"""
|
|
330
|
+
ret = p4.run_stream("-o")[0]
|
|
331
|
+
stream_name = ret["Stream"]
|
|
332
|
+
parent = ret["Parent"]
|
|
333
|
+
if ret["Type"] != "task":
|
|
334
|
+
abort(f"Current stream {stream_name} is not a task stream")
|
|
335
|
+
|
|
336
|
+
delete = confirm("Are you sure you want to delete the current task stream?")
|
|
337
|
+
if delete:
|
|
338
|
+
secho(f"Switching back to {parent}...")
|
|
339
|
+
p4.run_client("-s", "-S", parent)
|
|
340
|
+
|
|
341
|
+
secho(f"Deleting task stream {stream_name}...")
|
|
342
|
+
p4.run_stream("--obliterate", "-y", stream_name)
|
|
343
|
+
else:
|
|
344
|
+
abort("Aborted")
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
app.add_typer(task_app)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
0.3.1
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|