示例#1
0
def get_process_map():
    platform = sys.platform
    if 'linux' in platform:
        output = six.text_type(check_output_safe(LINUX_PS_COMMAND.split()))
        # Remove first line since it has the titles
        # and the last one which holds a null string
        lines = output.split('\\n')[1:-1]
        lines = map(lambda x: x.strip(), lines)
        processes = {}
        for line in lines:
            pid, cmd = line.split(' ', 1)  # Do not need regex since we used -o pid,cmd
            processes[int(pid)] = cmd
        return processes
    elif 'darwin' in platform:
        output = six.text_type(check_output_safe(OSX_PS_COMMAND.split()))
        # Remove first line since it has the titles
        # and the last one which holds a null string
        lines = output.split('\\n')[1:-1]
        lines = map(lambda x: x.strip(), lines)
        processes = {}
        for line in lines:
            pid, cmd = line.split(' ', 1)  # Do not need regex since we used -o pid,cmd
            processes[int(pid)] = cmd
        return processes
    else:
        raise UnsupportedPlatformError("{} does not implement get_process_map".format(
            platform
        ))
示例#2
0
 def __str__(self):
     cnd = "(?%s:" % self.name
     for cmps in self.if_set:
         if isinstance(cmps, six.integer_types):
             cnd += case_chars[cmps]
         else:
             cnd += escapeCharacters(six.text_type(cmps), "(:)")
     if self.if_not_set:
         cnd += ":"
         for cmps in self.if_not_set:
             if isinstance(cmps, six.integer_types):
                 cnd += case_chars[cmps]
             else:
                 cnd += escapeCharacters(six.text_type(cmps), "(:)")
     cnd += ")"
     return cnd
示例#3
0
文件: path.py 项目: D3f0/prymatex
def ensure_not_exists(path, name, suffix = 0):
    """Return a safe path, ensure not exists"""
    if suffix == 0 and not os.path.exists(path % name):
        return path % name
    else:
        newPath = path % (name + "_" + six.text_type(suffix))
        if not os.path.exists(newPath):
            return newPath
        else:
            return ensure_not_exists(path, name, suffix + 1)
示例#4
0
文件: syntax.py 项目: D3f0/prymatex
 def dump(self, allKeys = False):
     dataHash = super(Syntax, self).dump(allKeys)
     for key in Syntax.KEYS:
         value = getattr(self, key, None)
         if value is not None:
             if key == 'firstLineMatch':
                 value = value.pattern
             elif key == 'injectionSelector':
                 value = six.text_type(value)
             dataHash[key] = value
     return dataHash
示例#5
0
文件: server.py 项目: D3f0/prymatex
    def socketReadyRead(self):
        command = self.socket.recv_json()
        name = command.get("name")
        kwargs = command.get("kwargs", {})

        #TODO: Filtro todo lo que sea None asumo que las signaturas de los metodos ponene los valores por defecto
        # esto tendria que ser controlado de una mejor forma
        kwargs = dict([key_value for key_value in iter(kwargs.items()) if key_value[1] != None])
        
        self.logger.debug("Dialog Recv --> Method: %s, Arguments: %s" % (name, kwargs))
        method = getattr(self, name)
        try:
            method(**kwargs)
        except Exception as reason:
            self.sendResult({"error": {"code": -1, "message": six.text_type(reason)}})
            raise reason
示例#6
0
文件: win32.py 项目: D3f0/prymatex
def to_valid_name(name):
    name = unicodedata.normalize('NFKD', six.text_type(name)).encode('ASCII', 'ignore')
    return "".join([ c for c in name if c in VALID_PATH_CARACTERS ])
示例#7
0
import os
import sys
import subprocess
from prymatex.utils import six
from prymatex.core.exceptions import UnsupportedPlatformError


LINUX_PS_COMMAND = six.text_type('ps -eo pid,cmd')
OSX_PS_COMMAND = six.text_type('ps -eo pid,args')


def check_output_safe(*popenargs, **kwargs):
    '''Wrapper for bug http://bugs.python.org/issue6135'''
    if sys.version_info.major < 3:
        my_env = os.environ
        my_env['PYTHONIOENCODING'] = 'utf-8'
        kwargs.update(env=my_env)
        return subprocess.check_output(*popenargs, **kwargs).decode('utf-8', 'ignore')
    return subprocess.check_output(*popenargs, **kwargs)


def get_process_map():
    platform = sys.platform
    if 'linux' in platform:
        output = six.text_type(check_output_safe(LINUX_PS_COMMAND.split()))
        # Remove first line since it has the titles
        # and the last one which holds a null string
        lines = output.split('\\n')[1:-1]
        lines = map(lambda x: x.strip(), lines)
        processes = {}
        for line in lines:
示例#8
0
 def uuidtotext(uuid):
     return six.text_type(uuid).upper()
示例#9
0
文件: linux.py 项目: D3f0/prymatex
def to_valid_name(name):
    name = unicodedata.normalize('NFKD', six.text_type(name))
    return "".join([ c for c in six.text_type(name) if c in VALID_PATH_CARACTERS ])