Beispiel #1
0
    def _search_launchers(self, directories):
        INI_NAME = 'launcher.ini'
        CONFIG_DEFAULTS = {
            'name': 'Launcher',
            'command': '',
            'description': '',
            'image': '',
            'shell': 'false',
            'workdir': '.',
            'type': '',
            'manufacturer': '',
            'model': '',
            'variant': '',
            'priority': '0'
        }

        launchers = []
        ids = {}
        index = 0
        for root_dir in directories:
            for root, _, files in os.walk(root_dir):
                if INI_NAME not in files:
                    continue

                root = os.path.abspath(os.path.expanduser(root))
                iniFile = os.path.join(root, INI_NAME)
                cfg = configparser.ConfigParser(CONFIG_DEFAULTS)
                cfg.read(iniFile)
                for section in cfg.sections():
                    launcher = Launcher()
                    # descriptive data
                    launcher.name = cfg.get(section, 'name')
                    launcher.description = cfg.get(section, 'description')
                    info = MachineInfo()
                    info.type = cfg.get(section, 'type')
                    info.manufacturer = cfg.get(section, 'manufacturer')
                    info.model = cfg.get(section, 'model')
                    info.variant = cfg.get(section, 'variant')
                    launcher.priority = cfg.getint(section, 'priority')
                    launcher.importance = 0
                    launcher.info.MergeFrom(info)
                    # command data
                    launcher.command = cfg.get(section, 'command')
                    launcher.shell = cfg.getboolean(section, 'shell')
                    workdir = cfg.get(section, 'workdir')
                    if not os.path.isabs(workdir):
                        workdir = os.path.join(root, workdir)
                    launcher.workdir = os.path.normpath(workdir)
                    launcher.returncode = 0
                    launcher.running = False
                    launcher.terminating = False
                    # storing the image file
                    image_file = cfg.get(section, 'image')
                    if image_file is not '':
                        if not os.path.isabs(image_file):
                            image_file = os.path.join(root, image_file)
                        fileBuffer = open(image_file, 'rb').read()
                        image = File()
                        image.name = os.path.basename(image_file)
                        image.encoding = CLEARTEXT
                        image.blob = fileBuffer
                        launcher.image.MergeFrom(image)

                    launcher.index = index
                    index += 1
                    launchers.append(launcher)
                    ids[launcher.index] = '%s:%s' % (root, section)

        # sort using the priority attribute before distribution
        return sorted(launchers, key=attrgetter('priority'), reverse=True), ids
Beispiel #2
0
    def _search_launchers(self, directories):
        INI_NAME = 'launcher.ini'
        CONFIG_DEFAULTS = {
            'name': 'Launcher',
            'command': '',
            'description': '',
            'image': '',
            'shell': 'false',
            'workdir': '.',
            'type': '',
            'manufacturer': '',
            'model': '',
            'variant': '',
            'priority': '0'
        }

        launchers = []
        ids = {}
        index = 0
        for root_dir in directories:
            for root, _, files in os.walk(root_dir):
                if INI_NAME not in files:
                    continue

                root = os.path.abspath(os.path.expanduser(root))
                iniFile = os.path.join(root, INI_NAME)
                cfg = configparser.ConfigParser(CONFIG_DEFAULTS)
                cfg.read(iniFile)
                for section in cfg.sections():
                    launcher = Launcher()
                    # descriptive data
                    launcher.name = cfg.get(section, 'name')
                    launcher.description = cfg.get(section, 'description')
                    info = MachineInfo()
                    info.type = cfg.get(section, 'type')
                    info.manufacturer = cfg.get(section, 'manufacturer')
                    info.model = cfg.get(section, 'model')
                    info.variant = cfg.get(section, 'variant')
                    launcher.priority = cfg.getint(section, 'priority')
                    launcher.importance = 0
                    launcher.info.MergeFrom(info)
                    # command data
                    launcher.command = cfg.get(section, 'command')
                    launcher.shell = cfg.getboolean(section, 'shell')
                    workdir = cfg.get(section, 'workdir')
                    if not os.path.isabs(workdir):
                        workdir = os.path.join(root, workdir)
                    launcher.workdir = os.path.normpath(workdir)
                    launcher.returncode = 0
                    launcher.running = False
                    launcher.terminating = False
                    # storing the image file
                    image_file = cfg.get(section, 'image')
                    if image_file is not '':
                        if not os.path.isabs(image_file):
                            image_file = os.path.join(root, image_file)
                        fileBuffer = open(image_file, 'rb').read()
                        image = File()
                        image.name = os.path.basename(image_file)
                        image.encoding = CLEARTEXT
                        image.blob = fileBuffer
                        launcher.image.MergeFrom(image)

                    launcher.index = index
                    index += 1
                    launchers.append(launcher)
                    ids[launcher.index] = '%s:%s' % (root, section)

        # sort using the priority attribute before distribution
        return sorted(launchers, key=attrgetter('priority'), reverse=True), ids
Beispiel #3
0
    def _search_launchers(directories):
        ini_name = "launcher.ini"
        config_defaults = {
            "name": "Launcher",
            "command": "",
            "description": "",
            "image": "",
            "shell": "false",
            "workdir": ".",
            "type": "",
            "manufacturer": "",
            "model": "",
            "variant": "",
            "priority": "0",
        }

        launchers = []
        ids = {}
        index = 0
        for root_dir in directories:
            for root, _, files in os.walk(root_dir):
                if ini_name not in files:
                    continue

                root = os.path.abspath(os.path.expanduser(root))
                ini_file = os.path.join(root, ini_name)
                cfg = configparser.ConfigParser(config_defaults)
                cfg.read(ini_file)
                for section in cfg.sections():
                    launcher = Launcher()
                    # descriptive data
                    launcher.name = cfg.get(section, "name")
                    launcher.description = cfg.get(section, "description")
                    info = MachineInfo()
                    info.type = cfg.get(section, "type")
                    info.manufacturer = cfg.get(section, "manufacturer")
                    info.model = cfg.get(section, "model")
                    info.variant = cfg.get(section, "variant")
                    launcher.priority = cfg.getint(section, "priority")
                    launcher.importance = 0
                    launcher.info.MergeFrom(info)
                    # command data
                    launcher.command = cfg.get(section, "command")
                    launcher.shell = cfg.getboolean(section, "shell")
                    workdir = cfg.get(section, "workdir")
                    if not os.path.isabs(workdir):
                        workdir = os.path.join(root, workdir)
                    launcher.workdir = os.path.normpath(workdir)
                    launcher.returncode = 0
                    launcher.running = False
                    launcher.terminating = False
                    # storing the image file
                    image_file = cfg.get(section, "image")
                    if image_file != "":
                        if not os.path.isabs(image_file):
                            image_file = os.path.join(root, image_file)
                        file_buffer = open(image_file, "rb").read()
                        image = File()
                        image.name = os.path.basename(image_file)
                        image.encoding = CLEARTEXT
                        image.blob = file_buffer
                        launcher.image.MergeFrom(image)

                    launcher.index = index
                    index += 1
                    launchers.append(launcher)
                    ids[launcher.index] = "%s:%s" % (root, section)

        # sort using the priority attribute before distribution
        return sorted(launchers, key=attrgetter("priority"), reverse=True), ids