1
0
Fork 0
mirror of https://github.com/fastogt/pyfastogt synced 2025-03-09 23:38:55 +00:00

Some usefull functions

This commit is contained in:
topilski 2017-05-01 21:04:55 +03:00
parent 33f0dfd83d
commit 3ce89db833
3 changed files with 22 additions and 9 deletions

View file

@ -1,21 +1,24 @@
#!/usr/bin/env python #!/usr/bin/env python
import subprocess
import re import re
import subprocess
class MessageType: class MessageType:
STATUS = 1 STATUS = 1
MESSAGE = 2 MESSAGE = 2
class Message(object): class Message(object):
def __init__(self, message, type): def __init__(self, message, type):
self.message_ = message self.message_ = message
self.type_ = type self.type_ = type
def message(self): def message(self):
return self.message_ return self.message_
def type(self): def type(self):
return self.type_ return self.type_
class Policy(object): class Policy(object):
def __init__(self, cb): def __init__(self, cb):
@ -30,10 +33,12 @@ class Policy(object):
self.progress_ = progress self.progress_ = progress
self.process(Message(message, MessageType.STATUS)) self.process(Message(message, MessageType.STATUS))
class CommonPolicy(Policy): class CommonPolicy(Policy):
def __init__(self, cb): def __init__(self, cb):
Policy.__init__(self, cb) Policy.__init__(self, cb)
class CmakePolicy(Policy): class CmakePolicy(Policy):
def __init__(self, cb): def __init__(self, cb):
Policy.__init__(self, cb) Policy.__init__(self, cb)
@ -45,6 +50,7 @@ class CmakePolicy(Policy):
def update_progress_message(self, progress, message): def update_progress_message(self, progress, message):
super(CmakePolicy, self).update_progress_message(progress, message) super(CmakePolicy, self).update_progress_message(progress, message)
class MakePolicy(Policy): class MakePolicy(Policy):
def __init__(self, cb): def __init__(self, cb):
Policy.__init__(self, cb) Policy.__init__(self, cb)
@ -74,6 +80,7 @@ class MakePolicy(Policy):
return None return None
class NinjaPolicy(Policy): class NinjaPolicy(Policy):
def __init__(self, cb): def __init__(self, cb):
Policy.__init__(self, cb) Policy.__init__(self, cb)
@ -83,7 +90,7 @@ class NinjaPolicy(Policy):
super(NinjaPolicy, self).process(message) super(NinjaPolicy, self).process(message)
return 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: if not cur and not total:
return return
@ -103,9 +110,8 @@ class NinjaPolicy(Policy):
return None, None return None, None
def run_command_cb(cmd, policy):
if not policy: def run_command_cb(cmd: list, policy=Policy):
policy = Policy
try: try:
policy.update_progress_message(0.0, 'Command {0} started'.format(cmd)) policy.update_progress_message(0.0, 'Command {0} started'.format(cmd))
process = subprocess.Popen(cmd, stdout=subprocess.PIPE) 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))) policy.update_progress_message(100.0, 'Command {0} finished with exception {1}'.format(cmd, str(ex)))
raise ex raise ex
return rc return rc

View file

@ -276,3 +276,10 @@ SUPPORTED_BUILD_SYSTEMS = [BuildSystem('ninja', ['ninja'], '-GNinja'),
def get_supported_build_system_by_name(name) -> BuildSystem: def get_supported_build_system_by_name(name) -> BuildSystem:
return next((x for x in SUPPORTED_BUILD_SYSTEMS if x.name() == name), None) 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(":", '')

View file

@ -2,9 +2,9 @@
import os import os
import re import re
import shutil
import subprocess import subprocess
import tarfile import tarfile
import shutil
from urllib.request import urlopen from urllib.request import urlopen