kapsikkum-unmanic – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3  
4 """
5 unmanic.system.py
6  
7 Written by: Josh.5 <jsunnex@gmail.com>
8 Date: 05 Mar 2021, (11:00 PM)
9  
10 Copyright:
11 Copyright (C) Josh Sunnex - All Rights Reserved
12  
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19  
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22  
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
27 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
28 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
29 OR OTHER DEALINGS IN THE SOFTWARE.
30  
31 """
32 from unmanic.libs import unlogger, common
33 from unmanic.libs.singleton import SingletonType
34  
35  
36 class System(object, metaclass=SingletonType):
37 devices = {}
38 ffmpeg = {}
39 platform = {}
40 python_version = {}
41  
42 def __init__(self, *args, **kwargs):
43 unmanic_logging = unlogger.UnmanicLogger.__call__()
44 self.logger = unmanic_logging.get_logger(__class__.__name__)
45  
46 def _log(self, message, message2='', level="info"):
47 message = common.format_message(message, message2)
48 getattr(self.logger, level)(message)
49  
50 def __get_python_info(self):
51 """
52 Return a string of the python version
53  
54 :return:
55 """
56 import sys
57 if not self.python_version:
58 self.python_version = "{0}.{1}.{2}.{3}.{4}".format(*sys.version_info)
59 return self.python_version
60  
61 def __get_devices_info(self):
62 """
63 Return a dictionary of device information
64  
65 :return:
66 """
67 import cpuinfo
68 if not self.devices:
69 self.devices = {
70 "cpu_info": cpuinfo.get_cpu_info(),
71 "gpu_info": [],
72 }
73 return self.devices
74  
75 def __get_platform_info(self):
76 """
77 Return a dictionary of device information
78  
79 :return:
80 """
81 import platform
82 if not self.platform:
83 self.platform = platform.uname()
84 return self.platform
85  
86 def info(self):
87 """
88 Returns a dictionary of system information
89  
90 :return:
91 """
92 info = {
93 "devices": self.__get_devices_info(),
94 "platform": self.__get_platform_info(),
95 "python": self.__get_python_info(),
96 }
97 return info
98  
99  
100 if __name__ == "__main__":
101 import json
102 import sys
103 import os
104  
105 project_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
106 print(project_dir)
107 sys.path.append(project_dir)
108 system = System()
109 print(json.dumps(system.info(), indent=2))