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
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
return rc

View file

@ -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(":", '')

View file

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