Skip to content

Commit 49f13d9

Browse files
Merge pull request #738 from adobe-apiplatform/feature/info
Platform and environment info
2 parents 97ee5e4 + acb8442 commit 49f13d9

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

.build/pre_build.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import os
2222
import shutil
23+
import json
24+
import pkg_resources
25+
from pathlib import Path
2326
from backports import configparser
2427

2528

@@ -61,7 +64,14 @@ def bundle_feature_flag_config():
6164
flag_cfg.write(flag_cfg_file)
6265

6366

67+
def pkg_meta():
68+
pkg_meta_path = Path('user_sync', 'resources', 'pkg_meta.json')
69+
with open(pkg_meta_path, 'w') as f:
70+
json.dump({p.project_name: p.version for p in pkg_resources.working_set}, f)
71+
72+
6473
if __name__ == '__main__':
6574
cd()
6675
bundle_example_config('config files - basic')
6776
bundle_example_config('sign')
77+
pkg_meta()

.changelog/latest.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Features
2+
3+
* #738 Platform and environment info
4+
15
# Fixes
26

37
* df8b33d Prevent dynamic attribute error

user-sync.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ a = Analysis(['user_sync/app.py'],
66
binaries=[],
77
datas=[
88
('user_sync/resources/*.cfg', 'resources'),
9+
('user_sync/resources/*.json', 'resources'),
910
('user_sync/resources/manual_url', 'resources'),
1011
('user_sync/resources/README.md', 'resources'),
1112
('user_sync/resources/examples/*', 'resources/examples'),

user_sync/app.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import os
2222
import platform
2323
import sys
24+
import json
2425
from datetime import datetime
2526
from pathlib import Path
2627

@@ -40,7 +41,7 @@
4041
import user_sync.engine.umapi
4142
import user_sync.helper
4243
import user_sync.lockfile
43-
import user_sync.resource
44+
from user_sync import resource
4445
from user_sync.config.user_sync import UMAPIConfigLoader
4546
from user_sync.config.sign_sync import SignConfigLoader
4647
from user_sync.config import user_sync as config
@@ -100,6 +101,26 @@ def main():
100101
pass
101102

102103

104+
@main.command()
105+
@click.help_option('-h', '--help')
106+
def info():
107+
"""Get a dump of environmental information"""
108+
click.echo(f"Python: {platform.python_version()}")
109+
plat = platform.platform()
110+
click.echo(f"Platform: {plat}")
111+
if 'linux' in plat.lower():
112+
click.echo("OS Release Info:")
113+
with open('/etc/os-release') as f:
114+
for l in f:
115+
click.echo(f" {l.strip()}")
116+
click.echo("Packages:")
117+
pkg_meta_file = resource.get_resource('pkg_meta.json')
118+
with open(pkg_meta_file) as f:
119+
pkg_meta = json.load(f)
120+
for p in sorted(pkg_meta):
121+
click.echo(f" {p}: {pkg_meta[p]}")
122+
123+
103124
@main.command()
104125
@click.help_option('-h', '--help')
105126
@click.option('--config-file-encoding', 'encoding_name',
@@ -493,7 +514,7 @@ def shell_scripts(platform):
493514
"""Generate invocation shell scripts for the given platform."""
494515
if platform is None:
495516
platform = 'win' if 'win' in sys.platform.lower() else 'linux'
496-
shell_scripts = user_sync.resource.get_resource_dir('shell_scripts/{}'.format(platform))
517+
shell_scripts = resource.get_resource_dir('shell_scripts/{}'.format(platform))
497518
for script in shell_scripts:
498519
with open(script, 'r') as fh:
499520
content = fh.read()
@@ -509,7 +530,7 @@ def shell_scripts(platform):
509530
@click.help_option('-h', '--help')
510531
def docs():
511532
"""Open user manual in browser"""
512-
res_file = user_sync.resource.get_resource('manual_url')
533+
res_file = resource.get_resource('manual_url')
513534
assert res_file is not None, "User Manual URL file not found"
514535
with click.open_file(res_file) as f:
515536
url = f.read().strip()
@@ -535,7 +556,7 @@ def example_config(**kwargs):
535556
for k, fname in kwargs.items():
536557
target = Path.cwd() / fname
537558
assert k in res_files, "Invalid option specified"
538-
res_file = user_sync.resource.get_resource(res_files[k])
559+
res_file = resource.get_resource(res_files[k])
539560
assert res_file is not None, "Resource file '{}' not found".format(res_files[k])
540561
if target.exists() and not click.confirm('\nWarning - file already exists: \n{}\nOverwrite?'.format(target)):
541562
continue
@@ -565,7 +586,7 @@ def example_config_sign(**kwargs):
565586
for k, fname in kwargs.items():
566587
target = Path.cwd() / fname
567588
assert k in res_files, "Invalid option specified"
568-
res_file = user_sync.resource.get_resource(res_files[k])
589+
res_file = resource.get_resource(res_files[k])
569590
assert res_file is not None, "Resource file '{}' not found".format(res_files[k])
570591
if target.exists() and not click.confirm('\nWarning - file already exists: \n{}\nOverwrite?'.format(target)):
571592
continue

0 commit comments

Comments
 (0)