Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ __pycache__
venv
lock.pid
.env
.venv
44 changes: 30 additions & 14 deletions htpclient/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Copy link
Copy Markdown
Member

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?


@staticmethod
def get_version():
Expand Down Expand Up @@ -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'):
Expand Down Expand Up @@ -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"',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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"',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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)
Expand Down