-
Notifications
You must be signed in to change notification settings - Fork 64
In this changes added support Windows Server 2012 #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,3 +15,4 @@ __pycache__ | |
| venv | ||
| lock.pid | ||
| .env | ||
| .venv | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ | |
| class Initialize: | ||
| def __init__(self): | ||
| self.config = Config() | ||
| # In windows server and windows server R2 uses cp1251 encoding | ||
| self.encoding = "utf-8" | ||
|
|
||
| @staticmethod | ||
| def get_version(): | ||
|
|
@@ -64,7 +66,8 @@ def __login(self): | |
| os.mkdir("multicast") | ||
|
|
||
| def decode_output(self, output): | ||
| return output.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") | ||
| # Replace on dynamic variables for supporting windows cp1251 encoding | ||
| return output.decode(encoding=self.encoding).replace("\r\n", "\n").split("\n") | ||
|
|
||
| def __update_information(self): | ||
| if not self.config.get_value('uuid'): | ||
|
|
@@ -108,29 +111,42 @@ def __update_information(self): | |
|
|
||
| elif Initialize.get_os() == 1: # windows | ||
| platform_release = platform.uname().release | ||
| if platform_release == "" or int(platform_release) >= 10: | ||
| # This code for using on windows server 2012 and windows server 2012 R2 | ||
| try: | ||
| if platform_release == "" or int(platform_release) >= 10: | ||
| processor_information = subprocess.check_output( | ||
| 'powershell -Command "Get-CimInstance Win32_Processor | Select-Object -ExpandProperty Name"', | ||
| shell=True) | ||
| processor_information = self.decode_output(processor_information) | ||
| video_controller = subprocess.check_output( | ||
| 'powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name"', | ||
| shell=True) | ||
| video_controller = self.decode_output(video_controller) | ||
| else: | ||
| processor_information = subprocess.check_output( | ||
| 'wmic cpu get name', | ||
| shell=True) | ||
| processor_information = self.decode_output(processor_information) | ||
| video_controller = subprocess.check_output('wmic path win32_VideoController get name', shell=True) | ||
| video_controller = self.decode_output(video_controller) | ||
| except ValueError as ver: | ||
| pass | ||
|
|
||
| if platform_release == "2012ServerR2" or platform_release == "2012Server": | ||
| processor_information = subprocess.check_output( | ||
| 'powershell -Command "Get-CimInstance Win32_Processor | Select-Object -ExpandProperty Name"', | ||
| shell=True) | ||
| 'powershell -Command "Get-CimInstance Win32_Processor | Select-Object -ExpandProperty Name"', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this indentation is inconsistent with the other parts where the subprocess commands are called (indented twice instead of just once) |
||
| shell=True) | ||
| processor_information = self.decode_output(processor_information) | ||
| video_controller = subprocess.check_output( | ||
| 'powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name"', | ||
| shell=True) | ||
| video_controller = self.decode_output(video_controller) | ||
| else: | ||
| processor_information = subprocess.check_output( | ||
| 'wmic cpu get name', | ||
| shell=True) | ||
| processor_information = self.decode_output(processor_information) | ||
| video_controller = subprocess.check_output('wmic path win32_VideoController get name', shell=True) | ||
| 'powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name"', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this indentation is inconsistent with the other parts where the subprocess commands are called (indented twice instead of just once) |
||
| shell=True) | ||
| video_controller = self.decode_output(video_controller) | ||
|
|
||
| for source in (processor_information, video_controller): | ||
| for line in source: | ||
| line = line.rstrip("\r\n ") | ||
| if line and line != "Name": | ||
| devices.append(line) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this empty line helps for code readability, i.e. the section between linux and windows also is separated with an empty line, so it should remain also for consistency. |
||
| else: # OS X | ||
| output = subprocess.check_output("system_profiler SPDisplaysDataType -detaillevel mini", shell=True) | ||
| output = self.decode_output(output) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does this need to be set as variable here when the only place where it is used is where 'utf-8' was already enforced there? Or how is this supposed to be changed on the class?