2121import os
2222import platform
2323import sys
24+ import json
2425from datetime import datetime
2526from pathlib import Path
2627
4041import user_sync .engine .umapi
4142import user_sync .helper
4243import user_sync .lockfile
43- import user_sync . resource
44+ from user_sync import resource
4445from user_sync .config .user_sync import UMAPIConfigLoader
4546from user_sync .config .sign_sync import SignConfigLoader
4647from 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' )
510531def 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 ('\n Warning - file already exists: \n {}\n Overwrite?' .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 ('\n Warning - file already exists: \n {}\n Overwrite?' .format (target )):
571592 continue
0 commit comments