-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathackfetch.py
More file actions
71 lines (63 loc) · 3.05 KB
/
Copy pathackfetch.py
File metadata and controls
71 lines (63 loc) · 3.05 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
#!python3
# -*- coding: utf-8 -*-
import sys, os, pathlib, argparse, time
import logging
from populateSystemData import OSDetails
PyScript = pathlib.Path(os.path.abspath(__file__))
PyScriptRoot = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
def main():
args = _initArgParser().parse_args()
_initLogging(args.verbose)
deets = OSDetails.GetDetails()
noColors = args.noColors
print("")
if args.showAllProps:
hdrWidth = 14
_printDetail("Platform", deets.platform, hdrWidth, noColors)
_printDetail("Id", deets.id, hdrWidth, noColors)
_printDetail("Description", deets.description, hdrWidth, noColors)
_printDetail("Release", deets.release, hdrWidth, noColors)
_printDetail("ReleaseVersion", deets.releaseVersion, hdrWidth, noColors)
_printDetail("KernelVersion", deets.kernelVersion, hdrWidth, noColors)
if deets.buildNumber:
_printDetail("BuildNumber", deets.buildNumber, hdrWidth, noColors)
if deets.updateRevision:
_printDetail("UpdateRevision", deets.updateRevision, hdrWidth, noColors)
_printDetail("Distributor", deets.distributor, hdrWidth, noColors)
_printDetail("Codename", deets.codename, hdrWidth, noColors)
if deets.osType:
_printDetail("Type", deets.osType, hdrWidth, noColors)
if deets.edition:
_printDetail("Edition", deets.edition, hdrWidth, noColors)
_printDetail("OSArchitecture", deets.osArchitecture, hdrWidth, noColors)
_printDetail("Is64BitOS", deets.is64BitOS, hdrWidth, noColors)
else:
hdrWidth = 13
_printDetail("Description", deets.description, hdrWidth, noColors)
_printDetail("Id", deets.id, hdrWidth, noColors)
_printDetail("Distributor", deets.distributor, hdrWidth, noColors)
_printDetail("Codename", deets.codename, hdrWidth, noColors)
_printDetail("Release", deets.release, hdrWidth, noColors)
_printDetail("KernelVersion", deets.kernelVersion, hdrWidth, noColors)
def _printDetail(name: str, value: str, nameMinWidth: int, noColors: bool) -> None:
if noColors:
print(f"{name:<{nameMinWidth}} : {value}")
else:
print(f"\033[22m\033[32m\033[1m{name:<{nameMinWidth}} :\033[0m {value}")
def _initArgParser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser()
parser.add_argument("-a", "--showAllProps", action="store_true", help="show all properties rather than short list")
parser.add_argument("-n", "--noColors", action="store_true", help="no colors or ANSI formating")
parser.add_argument("-v", "--verbose", action="store_true", help="enable verbose logging")
return parser
def _initLogging(verbose : bool = False, useLocalTime : bool = False):
loglevel = logging.DEBUG if verbose else logging.INFO
if (useLocalTime):
logTimeFormat = "{asctime}.{msecs:0<3.0f}" + time.strftime('%z')
else:
logging.Formatter.converter = time.gmtime
logTimeFormat = "{asctime}.{msecs:0<3.0f}Z"
# see https://docs.python.org/3/library/logging.html#logrecord-attributes for things can include in format:
logging.basicConfig(level=loglevel, format=f"{logTimeFormat}|{{levelname:8}}|{{module}}|{{funcName}}|{{message}}", style='{', datefmt='%Y-%m-%d %H:%M:%S')
if __name__ == "__main__":
sys.exit(main())