unknown-cli 0.7.2__tar.gz → 0.7.3__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.
Files changed (22) hide show
  1. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/PKG-INFO +1 -1
  2. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/unknown_cli.egg-info/PKG-INFO +1 -1
  3. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/unknown_cli.egg-info/SOURCES.txt +1 -0
  4. unknown-cli-0.7.3/unknowncli/VERSION +1 -0
  5. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/unknowncli/__main__.py +0 -1
  6. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/unknowncli/commands/project.py +183 -27
  7. unknown-cli-0.7.3/unknowncli/set_registry_keys.py +22 -0
  8. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/unknowncli/utils.py +10 -5
  9. unknown-cli-0.7.2/unknowncli/VERSION +0 -1
  10. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/README.md +0 -0
  11. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/setup.cfg +0 -0
  12. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/setup.py +0 -0
  13. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/unknown_cli.egg-info/dependency_links.txt +0 -0
  14. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/unknown_cli.egg-info/entry_points.txt +0 -0
  15. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/unknown_cli.egg-info/requires.txt +0 -0
  16. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/unknown_cli.egg-info/top_level.txt +0 -0
  17. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/unknowncli/__init__.py +0 -0
  18. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/unknowncli/commands/__init__.py +0 -0
  19. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/unknowncli/commands/task.py +0 -0
  20. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/unknowncli/commands/unreal.py +0 -0
  21. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/unknowncli/data/.p4ignore.txt +0 -0
  22. {unknown-cli-0.7.2 → unknown-cli-0.7.3}/unknowncli/set_url_handler.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unknown-cli
3
- Version: 0.7.2
3
+ Version: 0.7.3
4
4
  Summary: Unknown Commandline Tool
5
5
  Home-page: UNKNOWN
6
6
  Author:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unknown-cli
3
- Version: 0.7.2
3
+ Version: 0.7.3
4
4
  Summary: Unknown Commandline Tool
5
5
  Home-page: UNKNOWN
6
6
  Author:
@@ -9,6 +9,7 @@ unknown_cli.egg-info/top_level.txt
9
9
  unknowncli/VERSION
10
10
  unknowncli/__init__.py
11
11
  unknowncli/__main__.py
12
+ unknowncli/set_registry_keys.py
12
13
  unknowncli/set_url_handler.py
13
14
  unknowncli/utils.py
14
15
  unknowncli/commands/__init__.py
@@ -0,0 +1 @@
1
+ 0.7.3
@@ -31,7 +31,6 @@ def cli(
31
31
  # console_handler.setLevel(getattr(logging, verbose.upper()))
32
32
  check_version()
33
33
  set_url_handler()
34
-
35
34
  check_p4config()
36
35
 
37
36
 
@@ -6,9 +6,9 @@ import socket
6
6
  from tabulate import tabulate
7
7
  from pathlib import Path
8
8
  from pprint import pprint
9
- from ..utils import dumps, abort, get_datafile
10
- from subprocess import check_call, call
11
- from P4 import P4
9
+ from ..utils import dumps, abort, get_datafile, PERFORCE_SERVERS
10
+ from subprocess import check_call, call, check_output
11
+ from P4 import P4, P4Exception
12
12
  import shutil
13
13
 
14
14
  log = logging.getLogger(__name__)
@@ -19,7 +19,18 @@ app = Typer()
19
19
 
20
20
  hostname = socket.gethostname().lower()
21
21
  SUBST_DRIVE = "S:"
22
- STREAMS = {"sn2-main": "//project/sn2-main-ue", "sandbox": "//project/sandbox"}
22
+ STREAMS = {
23
+ "sn2-main": "//project/sn2-main-ue"
24
+ }
25
+ SUB_STREAMS = {
26
+ "//project/sn2-main":
27
+ {
28
+ "Project ": "//project/sn2-main-ue",
29
+ "Project+Raw": "//project/sn2-main-ue-raw",
30
+ "Everything ": "//project/sn2-main",
31
+ }
32
+ }
33
+
23
34
  is_windows = os.name == "nt"
24
35
  DEFAULT_FOLDER = "C:\Work" if is_windows else "~/Work"
25
36
  MIN_FREE_GB = 200
@@ -33,8 +44,11 @@ def get_clientspecs(p4):
33
44
  ret = {}
34
45
  for s in specs:
35
46
  host = s["Host"].lower()
47
+ stream = s["Stream"].lower()
48
+ if stream not in ret:
49
+ ret[stream] = []
36
50
  if host == hostname or not host:
37
- ret[s["Stream"].lower()] = s
51
+ ret[stream].append(s)
38
52
  return ret
39
53
 
40
54
 
@@ -175,11 +189,17 @@ def setup(
175
189
  pass
176
190
  check_call(subst_cmd)
177
191
 
178
- import winreg
192
+ try:
193
+ import winreg
194
+ echo(f"Adding Virtual Drive {SUBST_DRIVE} -> {perforce_path} to startup")
195
+ h = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run")
196
+ winreg.SetValueEx(h, "Perforce Work Drive", 0, winreg.REG_SZ, subst_cmd)
197
+ except:
198
+ secho("Access denied setting subst registry key. Running elevated process...")
199
+ path = Path(__file__).parent.parent / "set_registry_keys.py"
200
+ cmd = f"python {path.resolve()} \"{subst_cmd}\""
201
+ check_call(cmd)
179
202
 
180
- echo(f"Adding Virtual Drive {SUBST_DRIVE} -> {perforce_path} to startup")
181
- h = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run")
182
- winreg.SetValueEx(h, "Perforce Work Drive", 0, winreg.REG_SZ, subst_cmd)
183
203
  h = winreg.CreateKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\perforce\environment")
184
204
  winreg.SetValueEx(h, "P4CONFIG", 0, winreg.REG_SZ, str(config_file))
185
205
 
@@ -193,7 +213,7 @@ def setup(
193
213
  "What would you like to call this computer in Perforce (work, home, laptop, etc)", default="work"
194
214
  )
195
215
  if not computer_name.isalpha() or computer_name != computer_name.lower():
196
- abort("Computer name must be lowercase with no symbols")
216
+ abort("Computer name must be lowercase with no symbols or numbers")
197
217
  for stream_name, stream in STREAMS.items():
198
218
  mapping = f"{root_path}/{stream_name}"
199
219
  found = False
@@ -221,10 +241,10 @@ def setup(
221
241
  p = Path(mapping)
222
242
  p.mkdir(parents=True, exist_ok=True)
223
243
 
224
- secho("\nProject setup has been completed. Please sync your workspaces through p4v", fg="green")
225
- secho(
226
- "Unreal Game Sync documentation: https://www.notion.so/unknownworlds/How-To-Setup-Unreal-Game-Sync-59cc3348cdde449d8fdc7f39ee60c8b3"
227
- )
244
+ secho("\nProject setup has been completed. Please sync your workspace through p4v.", fg="green")
245
+ secho("\n * Unreal Game Sync documentation: https://www.notion.so/unknownworlds/How-To-Setup-Unreal-Game-Sync-59cc3348cdde449d8fdc7f39ee60c8b3")
246
+ secho(" * If you are located in Europe or Asia please run `unk project migrate` to access the appropriate edge server.")
247
+ secho(" * If you require Raw content please run `unk project stream` to switch to the appropriate virtual stream")
228
248
  # sync_workspaces()
229
249
 
230
250
 
@@ -235,6 +255,121 @@ def sync(stream: str = Option(""), force: bool = Option(False)):
235
255
  """
236
256
  sync_workspaces(stream, force)
237
257
 
258
+ @app.command()
259
+ def stream():
260
+ """
261
+ Switch your current workspace to a virtual stream of your choosing
262
+ """
263
+ p4 = P4()
264
+ p4.connect()
265
+ specs = get_clientspecs(p4)
266
+ client = p4.run_client("-o")[0]
267
+ stream = p4.run_stream("-o")[0]
268
+ current_stream_name = client["Stream"].lower()
269
+ secho(f"Your workspace {p4.client} are currently on stream {current_stream_name}")
270
+ parent_stream = stream.get("Parent", "").lower()
271
+ if not parent_stream or parent_stream == "none":
272
+ parent_stream = current_stream_name
273
+ if parent_stream not in SUB_STREAMS:
274
+ abort(f"Your workspace has an invalid parent stream '{parent_stream}'")
275
+ secho(f"Which stream from parent {parent_stream} would you like to use?\n")
276
+ i = 1
277
+ for desc, stream_name in SUB_STREAMS[parent_stream].items():
278
+ secho(f"{i}\t{desc}\t{stream_name}")
279
+ i += 1
280
+ n = prompt("\nSelect a stream to work in")
281
+ try:
282
+ n = int(n)-1
283
+ vals = list(SUB_STREAMS[parent_stream].values())
284
+ if n < 0 or n > len(vals):
285
+ raise Exception
286
+ new_stream = vals[n]
287
+ except:
288
+ raise
289
+ abort("Aborted.")
290
+ secho(f"\nSwitching to stream {new_stream}", bold=True)
291
+ try:
292
+ p4.run_client("-s", "-S", new_stream)
293
+ except P4Exception as e:
294
+ abort(e)
295
+
296
+ from enum import Enum
297
+ class Region(str, Enum):
298
+ USA = "USA"
299
+ Europe = "Europe"
300
+ Asia = "Asia"
301
+
302
+ @app.command()
303
+ def region():
304
+ """
305
+ Migrate your perforce connection to one of the edge regions.
306
+ https://www.notion.so/unknownworlds/How-To-Migrating-an-existing-workspace-b5adb9ef4a3e4e32a4b7b212df1e70e0#d90ecb2206ae4c2490c4752ed0ce89ea
307
+ """
308
+ p4 = P4()
309
+ p4.connect()
310
+ name = ""
311
+ for k, v in PERFORCE_SERVERS.items():
312
+ if v.lower() == p4.port.lower():
313
+ name = k
314
+ if name:
315
+ secho(f"You are currently on edge perforce server {name} ({p4.port})")
316
+ else:
317
+ secho(f"You are currently on the primary perforce server {p4.port}")
318
+ regions = ", ".join([k for k in PERFORCE_SERVERS.keys() if k])
319
+ region = prompt(f"Select region to migrate to (usa, {regions})")
320
+ region = region.lower()
321
+ my_specs = get_clientspecs(p4)
322
+ current_port = p4.port
323
+ if region == "usa":
324
+ region = ""
325
+ try:
326
+ p4_port = PERFORCE_SERVERS[region]
327
+ except:
328
+ abort("Please select a legitimate server")
329
+ us_p4_port = PERFORCE_SERVERS[""]
330
+ #if p4.port != us_p4_port:
331
+ # abort(f"You can only migrate your connection from {us_p4_port}. You are currently on {current_port}")
332
+
333
+ cfg = Path(p4.env('P4CONFIG'))
334
+
335
+ #if p4.port.lower() == p4_port:
336
+ # secho("You are already connected to the requested region", fg="green")
337
+ # return
338
+
339
+ secho(f"Logging you into server {p4_port}...")
340
+ try:
341
+ check_call(f"p4 -p {p4_port} login -a")
342
+ except Exception as e:
343
+ abort("Could not log you in. Wrong password?")
344
+
345
+ #
346
+ for specs in my_specs.values():
347
+ for spec in specs:
348
+ server_id = spec.get("ServerID", "")
349
+ client_name = spec["client"]
350
+ prev_server = PERFORCE_SERVERS.get(server_id)
351
+ if server_id not in PERFORCE_SERVERS:
352
+ secho(f"Server '{server_id}' in workspace {client_name} not found", fg="yellow")
353
+ if prev_server == p4_port:
354
+ secho(f"Workspace {client_name} already on server {server_id}", fg="yellow")
355
+ secho(f"Moving {client_name} from {prev_server} to {p4_port}...")
356
+ try:
357
+ check_output(f"p4 -p {p4_port} reload -c {client_name} -p {prev_server}")
358
+ except Exception as e:
359
+ secho(f"Error moving {client_name}.", fg="red")
360
+ secho(f"Updating your perforce config file {str(cfg)}...")
361
+ _lines = []
362
+ lines = []
363
+ with cfg.open() as f:
364
+ _lines = f.readlines()
365
+ for l in _lines:
366
+ if not l.upper().startswith("P4PORT"):
367
+ lines.append(l)
368
+ lines.append(f"P4PORT={p4_port}\n")
369
+ with cfg.open("w") as f:
370
+ f.writelines(lines)
371
+
372
+ secho(f"\nMigration completed. Make sure Rider, p4v and the Unreal editor are all configured to use '{p4_port}'", fg="green")
238
373
 
239
374
  def sync_workspaces(stream="", force=False):
240
375
  files_completed = 0
@@ -254,7 +389,7 @@ def sync_workspaces(stream="", force=False):
254
389
  if not stream:
255
390
  options = style("Available streams:\n", bold=True)
256
391
  for i, s in enumerate(STREAMS.values(), 1):
257
- folder = specs[s.lower()]["Root"]
392
+ folder = specs[s.lower()][0]["Root"]
258
393
  options += f" {i}: {s} -> {folder}\n"
259
394
  options += f" 0: ALL\n"
260
395
  options += "\n\nWhich Stream would you like to sync?"
@@ -274,9 +409,9 @@ def sync_workspaces(stream="", force=False):
274
409
  for stream_name, s in STREAMS.items():
275
410
  if stream not in s:
276
411
  continue
277
- folder = specs[s.lower()]["Root"]
412
+ folder = specs[s.lower()][0]["Root"]
278
413
  echo(f"Syncing {s} -> {folder}...")
279
- p4.client = specs[s]["client"]
414
+ p4.client = specs[s][0]["client"]
280
415
  stats = get_sync_stats(p4, force)
281
416
  num_files = stats["files"]["total"]
282
417
  batch_size = 1000
@@ -304,24 +439,45 @@ def sync_workspaces(stream="", force=False):
304
439
 
305
440
 
306
441
  @app.command()
307
- def workspaces():
442
+ def workspaces(selective: bool = Option(True), sn2: bool = Option(False), all: bool = Option(False)):
308
443
  """
309
444
  Shows a list of your perforce workspaces
310
445
  """
311
- p4 = P4()
312
- p4.connect()
313
- try:
314
- ret = p4.run_clients("-u", p4.user)
315
- except Exception as e:
316
- if "P4PASSWD" in str(e):
317
- abort("Please log into perforce with p4 login")
446
+ ret = []
447
+ for k, v in PERFORCE_SERVERS.items():
448
+ p4 = P4()
449
+ p4.port = v
450
+ p4.connect()
451
+
452
+ secho(f"Querying {p4.port}...")
453
+ try:
454
+ if all:
455
+ r = p4.run_clients()
456
+ else:
457
+ r = p4.run_clients("-u", p4.user)
458
+ ret.extend(r)
459
+ except Exception as e:
460
+ print(e)
461
+ # todo: retry
462
+ p4.run_login()
463
+
464
+ from operator import itemgetter
465
+ for r in ret:
466
+ r["Owner"] = r["Owner"].lower()
467
+ ret.sort(key=itemgetter("Owner"))
318
468
  rows = []
319
469
  for r in ret:
470
+ if "Stream" not in r:
471
+ continue
472
+ if sn2 and "sn2-main" not in r["Stream"].lower():
473
+ continue
474
+ if selective and (r["Owner"] == "build" or r["client"].startswith("swarm")):
475
+ continue
320
476
  h = r["Host"]
321
477
  if h.lower() == socket.gethostname().lower():
322
478
  h = style(h, bold=True)
323
479
  else:
324
480
  h = style(h, fg="red")
325
- rows.append([r["client"], r["Stream"], r["Root"], h])
326
- tbl = tabulate(rows, headers=["Client", "Stream", "Root", "Host"])
481
+ rows.append([r["Owner"], r["client"], r["Stream"], r["Root"][:32], h, r.get("ServerID")])
482
+ tbl = tabulate(rows, headers=["Owner", "Client", "Stream", "Root", "Host", "Server"])
327
483
  echo(tbl)
@@ -0,0 +1,22 @@
1
+ """
2
+ sets the s:/ subst command in registry, elevates access if needed.
3
+ Include the full value in quotes when calling this script. e.g. `set_registry_keys.py "subst S: d:\Perforce"`
4
+ """
5
+ import pyuac, winreg, sys
6
+ from os import getcwd
7
+
8
+ handler_name = "sn2"
9
+ key = f"{handler_name}\shell\open\command"
10
+
11
+ @pyuac.main_requires_admin
12
+ def main(subst_cmd):
13
+ try:
14
+ run_key = "Software\Microsoft\Windows\CurrentVersion\Run"
15
+ h = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, run_key)
16
+ winreg.SetValueEx(h, "Perforce Work Drive", 0, winreg.REG_SZ, subst_cmd)
17
+
18
+ except PermissionError as e:
19
+ print(f"Unable to set subst command. Please open up your shell as Administrator (through shift-right click menu) and run this command again ({str(e)})")
20
+
21
+ if __name__ == "__main__":
22
+ main(sys.argv[1])
@@ -19,6 +19,8 @@ import json
19
19
  import botocore
20
20
  from loguru import logger
21
21
  from pathlib import Path
22
+ from P4 import P4
23
+
22
24
  try:
23
25
  import winreg
24
26
  except:
@@ -37,6 +39,11 @@ root_logger.addHandler(console_handler)
37
39
 
38
40
  log = logging.getLogger(__name__)
39
41
 
42
+ PERFORCE_SERVERS = {
43
+ "": "ssl:perforce.reginald.cloud:1666",
44
+ "europe-edge": "ssl:perforce-europe.reginald.cloud:1666",
45
+ "asia-edge": "ssl:perforce-asia.reginald.cloud:1666"
46
+ }
40
47
 
41
48
  def print_error(*txt):
42
49
  color_print(*txt, color="red")
@@ -240,10 +247,7 @@ def check_p4config():
240
247
  is_changes = False
241
248
  p4 = P4()
242
249
  ignore_file = "s:\\sn2-main\\.p4ignore.txt".lower()
243
- p4_ports = [
244
- "ssl:perforce.reginald.cloud:1666",
245
- "ssl:perforce-europe.reginald.cloud:1666",
246
- "ssl:perforce-asia.reginald.cloud:1666",]
250
+ p4_ports = list(PERFORCE_SERVERS.values())
247
251
  cfg = Path(p4.env('P4CONFIG'))
248
252
  if p4.ignore_file == "unset":
249
253
  return
@@ -288,9 +292,10 @@ def check_p4config():
288
292
 
289
293
  secho("\nYou're all set!", fg="green")
290
294
  exit(0)
295
+ #secho("p4 config looks good")
291
296
 
292
297
  except Exception as e:
293
- pass
298
+ secho("Exception in check_p4_config: {e}", fg="yellow")
294
299
 
295
300
  def set_url_handler(force=False):
296
301
  exe = Path(sys.argv[0] + ".exe")
@@ -1 +0,0 @@
1
- 0.7.2
File without changes
File without changes
File without changes