diff --git a/base/run_command.py b/base/run_command.py index 7f6230d..c46352d 100644 --- a/base/run_command.py +++ b/base/run_command.py @@ -1,21 +1,24 @@ #!/usr/bin/env python -import subprocess import re +import subprocess + class MessageType: STATUS = 1 MESSAGE = 2 + class Message(object): def __init__(self, message, type): self.message_ = message self.type_ = type def message(self): - return self.message_ + return self.message_ def type(self): - return self.type_ + return self.type_ + class Policy(object): def __init__(self, cb): @@ -30,10 +33,12 @@ class Policy(object): self.progress_ = progress self.process(Message(message, MessageType.STATUS)) + class CommonPolicy(Policy): def __init__(self, cb): Policy.__init__(self, cb) + class CmakePolicy(Policy): def __init__(self, cb): Policy.__init__(self, cb) @@ -45,6 +50,7 @@ class CmakePolicy(Policy): def update_progress_message(self, progress, message): super(CmakePolicy, self).update_progress_message(progress, message) + class MakePolicy(Policy): def __init__(self, cb): Policy.__init__(self, cb) @@ -74,6 +80,7 @@ class MakePolicy(Policy): return None + class NinjaPolicy(Policy): def __init__(self, cb): Policy.__init__(self, cb) @@ -83,7 +90,7 @@ class NinjaPolicy(Policy): super(NinjaPolicy, self).process(message) return - cur,total = self.parse_message_to_get_range(message.message()) + cur, total = self.parse_message_to_get_range(message.message()) if not cur and not total: return @@ -103,9 +110,8 @@ class NinjaPolicy(Policy): return None, None -def run_command_cb(cmd, policy): - if not policy: - policy = Policy + +def run_command_cb(cmd: list, policy=Policy): try: policy.update_progress_message(0.0, 'Command {0} started'.format(cmd)) process = subprocess.Popen(cmd, stdout=subprocess.PIPE) @@ -118,4 +124,4 @@ def run_command_cb(cmd, policy): policy.update_progress_message(100.0, 'Command {0} finished with exception {1}'.format(cmd, str(ex))) raise ex - return rc \ No newline at end of file + return rc diff --git a/base/system_info.py b/base/system_info.py index 501fe81..2a82362 100644 --- a/base/system_info.py +++ b/base/system_info.py @@ -276,3 +276,10 @@ SUPPORTED_BUILD_SYSTEMS = [BuildSystem('ninja', ['ninja'], '-GNinja'), def get_supported_build_system_by_name(name) -> BuildSystem: return next((x for x in SUPPORTED_BUILD_SYSTEMS if x.name() == name), None) + + +def stable_path(path) -> str: + if get_os() == 'windows': + return '/' + path.replace("\\", "/").replace(":", '') + + return path.replace("\\", "/").replace(":", '') diff --git a/base/utils.py b/base/utils.py index d403612..ed7c94e 100644 --- a/base/utils.py +++ b/base/utils.py @@ -2,9 +2,9 @@ import os import re +import shutil import subprocess import tarfile -import shutil from urllib.request import urlopen