Python os.sep() Examples

The following are 30 code examples for showing how to use os.sep(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module os , or try the search function .

Example 1
Project: vergeml   Author: mme   File: io.py    License: MIT License 6 votes vote down vote up
def scan(self, path, exclude=[]) -> List[str]:
        """Scan path for matching files.

        :param path: the path to scan
        :param exclude: a list of directories to exclude

        :return: a list of sorted filenames
        """
        res = []
        path = path.rstrip("/").rstrip("\\")
        for pat in self.input_patterns:
            res.extend(glob.glob(path + os.sep + pat, recursive=True))

        res = list(filter(lambda p: os.path.isfile(p), res))

        if exclude:
            def excluded(path):
                for e in exclude:
                    if path.startswith(e):
                        return True
                return False

            res = list(filter(lambda p: not excluded(p), res))

        return sorted(res) 
Example 2
Project: multibootusb   Author: mbusb   File: osdriver.py    License: GNU General Public License v2.0 6 votes vote down vote up
def resource_path(relativePath):
    """
    Function to detect the correct path of file when working with sourcecode/install or binary.
    :param relativePath: Path to file/data.
    :return: Modified path to file/data.
    """
    # This is not strictly needed because Windows recognize '/'
    # as a path separator but we follow the discipline here.
    relativePath = relativePath.replace('/', os.sep)
    for dir_ in [
            os.path.abspath('.'),
            os.path.abspath('..'),
            getattr(sys, '_MEIPASS', None),
            os.path.dirname(os.path.dirname( # go up two levels
                os.path.realpath(__file__))),
            '/usr/share/multibootusb'.replace('/', os.sep),
            ]:
        if dir_ is None:
            continue
        fullpath = os.path.join(dir_, relativePath)
        if os.path.exists(fullpath):
            return fullpath
    log("Could not find resource '%s'." % relativePath) 
Example 3
Project: multibootusb   Author: mbusb   File: _device.py    License: GNU General Public License v2.0 6 votes vote down vote up
def from_path(cls, context, path):
        """
        Create a device from a device ``path``.  The ``path`` may or may not
        start with the ``sysfs`` mount point:

        >>> from pyudev import Context, Device
        >>> context = Context()
        >>> Devices.from_path(context, '/devices/platform')
        Device(u'/sys/devices/platform')
        >>> Devices.from_path(context, '/sys/devices/platform')
        Device(u'/sys/devices/platform')

        ``context`` is the :class:`Context` in which to search the device.
        ``path`` is a device path as unicode or byte string.

        Return a :class:`Device` object for the device.  Raise
        :exc:`DeviceNotFoundAtPathError`, if no device was found for ``path``.

        .. versionadded:: 0.18
        """
        if not path.startswith(context.sys_path):
            path = os.path.join(context.sys_path, path.lstrip(os.sep))
        return cls.from_sys_path(context, path) 
Example 4
Project: multibootusb   Author: mbusb   File: debug.py    License: GNU General Public License v2.0 6 votes vote down vote up
def fnCall():
    """
    Prints filename:line:function for parent and grandparent.
    """

    if not config.debug:
        return

    print(colors.OKGREEN + colors.BOLD + "=== DEBUG === | %s:%d:%s() called from %s:%d:%s()" % (
        inspect.stack()[1][1].split(os.sep)[-1],
        inspect.stack()[1][2],
        inspect.stack()[1][3],
        inspect.stack()[2][1].split(os.sep)[-1],
        inspect.stack()[2][2],
        inspect.stack()[2][3],
        )+colors.RESET) 
Example 5
Project: dynamic-training-with-apache-mxnet-on-aws   Author: awslabs   File: lint.py    License: Apache License 2.0 6 votes vote down vote up
def get_header_guard_dmlc(filename):
    """Get Header Guard Convention for DMLC Projects.

    For headers in include, directly use the path
    For headers in src, use project name plus path

    Examples: with project-name = dmlc
        include/dmlc/timer.h -> DMLC_TIMTER_H_
        src/io/libsvm_parser.h -> DMLC_IO_LIBSVM_PARSER_H_
    """
    fileinfo = cpplint.FileInfo(filename)
    file_path_from_root = fileinfo.RepositoryName()
    inc_list = ['include', 'api', 'wrapper']

    if file_path_from_root.find('src/') != -1 and _HELPER.project_name is not None:
        idx = file_path_from_root.find('src/')
        file_path_from_root = _HELPER.project_name +  file_path_from_root[idx + 3:]
    else:
        for spath in inc_list:
            prefix = spath + os.sep
            if file_path_from_root.startswith(prefix):
                file_path_from_root = re.sub('^' + prefix, '', file_path_from_root)
                break
    return re.sub(r'[-./\s]', '_', file_path_from_root).upper() + '_' 
Example 6
Project: dynamic-training-with-apache-mxnet-on-aws   Author: awslabs   File: lint.py    License: Apache License 2.0 6 votes vote down vote up
def get_header_guard_dmlc(filename):
    """Get Header Guard Convention for DMLC Projects.
    For headers in include, directly use the path
    For headers in src, use project name plus path
    Examples: with project-name = dmlc
        include/dmlc/timer.h -> DMLC_TIMTER_H_
        src/io/libsvm_parser.h -> DMLC_IO_LIBSVM_PARSER_H_
    """
    fileinfo = cpplint.FileInfo(filename)
    file_path_from_root = fileinfo.RepositoryName()
    inc_list = ['include', 'api', 'wrapper']

    if file_path_from_root.find('src/') != -1 and _HELPER.project_name is not None:
        idx = file_path_from_root.find('src/')
        file_path_from_root = _HELPER.project_name +  file_path_from_root[idx + 3:]
    else:
        for spath in inc_list:
            prefix = spath + os.sep
            if file_path_from_root.startswith(prefix):
                file_path_from_root = re.sub('^' + prefix, '', file_path_from_root)
                break
    return re.sub(r'[-./\s]', '_', file_path_from_root).upper() + '_' 
Example 7
Project: pruning_yolov3   Author: zbyuan   File: datasets.py    License: GNU General Public License v3.0 6 votes vote down vote up
def convert_images2bmp():
    # cv2.imread() jpg at 230 img/s, *.bmp at 400 img/s
    for path in ['../coco/images/val2014/', '../coco/images/train2014/']:
        folder = os.sep + Path(path).name
        output = path.replace(folder, folder + 'bmp')
        if os.path.exists(output):
            shutil.rmtree(output)  # delete output folder
        os.makedirs(output)  # make new output folder

        for f in tqdm(glob.glob('%s*.jpg' % path)):
            save_name = f.replace('.jpg', '.bmp').replace(folder, folder + 'bmp')
            cv2.imwrite(save_name, cv2.imread(f))

    for label_path in ['../coco/trainvalno5k.txt', '../coco/5k.txt']:
        with open(label_path, 'r') as file:
            lines = file.read()
        lines = lines.replace('2014/', '2014bmp/').replace('.jpg', '.bmp').replace(
            '/Users/glennjocher/PycharmProjects/', '../')
        with open(label_path.replace('5k', '5k_bmp'), 'w') as file:
            file.write(lines) 
Example 8
Project: mx   Author: graalvm   File: mx_ide_eclipse.py    License: GNU General Public License v2.0 6 votes vote down vote up
def get_eclipse_project_rel_locationURI(path, eclipseProjectDir):
    """
    Gets the URI for a resource relative to an Eclipse project directory (i.e.,
    the directory containing the `.project` file for the project). The URI
    returned is based on the builtin PROJECT_LOC Eclipse variable.
    See http://stackoverflow.com/a/7585095
    """
    relpath = os.path.relpath(path, eclipseProjectDir)
    names = relpath.split(os.sep)
    parents = len([n for n in names if n == '..'])
    sep = '/' # Yes, even on Windows...
    if parents:
        projectLoc = 'PARENT-{}-PROJECT_LOC'.format(parents)
    else:
        projectLoc = 'PROJECT_LOC'
    return sep.join([projectLoc] + [n for n in names if n != '..']) 
Example 9
Project: dockerfiles   Author: floydhub   File: utils.py    License: Apache License 2.0 6 votes vote down vote up
def gen_dockerfile_path_from_tag(img_tag):
    """
    sample input: 'tensorflow:1.0.1-gpu-py3'
    sample output: 'dl/tensorflow/1.0.1/Dockerfile-py3.gpu'
    """
    match = docker_tag_re.match(img_tag)
    if not match:
        return None

    path_list = ['dl', match.group('project'), match.group('version')]
    filename = 'Dockerfile-' + match.group('env')
    arch = match.group('arch')
    if arch:
        filename += '.' + arch
    cloud = match.group('cloud')
    if cloud:
        filename += '_' + cloud

    path_list.append(filename)
    return os.path.sep.join(path_list) 
Example 10
Project: L3C-PyTorch   Author: fab-jul   File: saver.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, out_dir=None, ckpt_name_fmt='ckpt_{:010d}.pt', tmp_postfix='.tmp'):
        assert len(tmp_postfix)
        assert '.' in tmp_postfix
        m = re.search(r'{:0(\d+?)d}', ckpt_name_fmt)
        assert m, 'Expected ckpt_name_fmt to have an int specifier such as or {:09d} or {:010d}.'
        max_itr = 10 ** int(m.group(1)) - 1
        if max_itr < 10000000:  # ten million, should be enough
            print(f'Maximum iteration supported: {max_itr}')
        assert os.sep not in ckpt_name_fmt
        self.ckpt_name_fmt = ckpt_name_fmt
        self.ckpt_prefix = ckpt_name_fmt.split('{')[0]
        assert len(self.ckpt_prefix), 'Expected ckpt_name_fmt to start with a prefix before the format part!'
        self.tmp_postfix = tmp_postfix

        self._out_dir = None
        if out_dir is not None:
            self.set_out_dir(out_dir) 
Example 11
Project: overhaul-distillation   Author: clovaai   File: cityscapes.py    License: MIT License 6 votes vote down vote up
def __getitem__(self, index):

        img_path = self.files[self.split][index].rstrip()
        lbl_path = os.path.join(self.annotations_base,
                                img_path.split(os.sep)[-2],
                                os.path.basename(img_path)[:-15] + 'gtFine_labelIds.png')

        _img = Image.open(img_path).convert('RGB')
        _tmp = np.array(Image.open(lbl_path), dtype=np.uint8)
        _tmp = self.encode_segmap(_tmp)
        _target = Image.fromarray(_tmp)

        sample = {'image': _img, 'label': _target}

        if self.split == 'train':
            return self.transform_tr(sample)
        elif self.split == 'val':
            return self.transform_val(sample)
        elif self.split == 'test':
            return self.transform_ts(sample) 
Example 12
Project: Yolo-v2-pytorch   Author: uvipen   File: convert_coco_to_pkl.py    License: MIT License 6 votes vote down vote up
def main(opt):
    ann_file = '{}/annotations/instances_{}.json'.format(opt.input, opt.type)
    dataset = json.load(open(ann_file, 'r'))
    image_dict = {}
    invalid_anno = 0

    for image in dataset["images"]:
        if image["id"] not in image_dict.keys():
            image_dict[image["id"]] = {"file_name": image["file_name"], "objects": []}

    for ann in dataset["annotations"]:
        if ann["image_id"] not in image_dict.keys():
            invalid_anno += 1
            continue
        image_dict[ann["image_id"]]["objects"].append(
            [int(ann["bbox"][0]), int(ann["bbox"][1]), int(ann["bbox"][0] + ann["bbox"][2]),
             int(ann["bbox"][1] + ann["bbox"][3]), ann["category_id"]])

    pickle.dump(image_dict, open(opt.output + os.sep + 'COCO_{}.pkl'.format(opt.type), 'wb'))
    print ("There are {} invalid annotation(s)".format(invalid_anno)) 
Example 13
Project: freshpaper   Author: guptarohit   File: freshpaper.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def get_wallpaper_directory():
    """ check if `default` wallpaper download directory exists or not, create if doesn't exist """
    pictures_dir = ""
    wall_dir_name = "freshpaper"
    os.path.join(os.sep, os.path.expanduser("~"), "a", "freshpaper")
    if sys.platform.startswith("win32"):
        pictures_dir = "My Pictures"
    elif sys.platform.startswith("darwin"):
        pictures_dir = "Pictures"
    elif sys.platform.startswith("linux"):
        pictures_dir = "Pictures"
    wall_dir = os.path.join(
        os.sep, os.path.expanduser("~"), pictures_dir, wall_dir_name
    )

    if not os.path.isdir(wall_dir):
        log.error("wallpaper directory does not exist.")
        os.makedirs(wall_dir)
        log.info("created wallpaper directory at: {}".format(wall_dir))

    return wall_dir 
Example 14
Project: me-ica   Author: ME-ICA   File: freeze.py    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
def get_resource_path(*args):
  if is_frozen():
    # MEIPASS explanation:
    # https://pythonhosted.org/PyInstaller/#run-time-operation
    basedir = getattr(sys, '_MEIPASS', None)
    if not basedir:
      basedir = os.path.dirname(sys.executable)
    resource_dir = os.path.join(basedir, 'gooey')
    if not os.path.isdir(resource_dir):
      raise IOError(
        ("Cannot locate Gooey resources. It seems that the program was frozen, "
         "but resource files were not copied into directory of the executable "
         "file. Please copy `languages` and `images` folders from gooey module "
         "directory into `{}{}` directory. Using PyInstaller, a.datas in .spec "
         "file must be specified.".format(resource_dir, os.sep)))
  else:
    resource_dir = os.path.normpath(os.path.join(os.path.dirname(__file__), '..', '..'))
  return os.path.join(resource_dir, *args) 
Example 15
Project: zun   Author: openstack   File: loadables.py    License: Apache License 2.0 6 votes vote down vote up
def get_all_classes(self):
        """Get all classes

        Get the classes of the type we want from all modules found
        in the directory that defines this class.
        """
        classes = []
        for dirpath, dirnames, filenames in os.walk(self.path):
            relpath = os.path.relpath(dirpath, self.path)
            if relpath == '.':
                relpkg = ''
            else:
                relpkg = '.%s' % '.'.join(relpath.split(os.sep))
            for fname in filenames:
                root, ext = os.path.splitext(fname)
                if ext != '.py' or root == '__init__':
                    continue
                module_name = "%s%s.%s" % (self.package, relpkg, root)
                mod_classes = self._get_classes_from_module(module_name)
                classes.extend(mod_classes)
        return classes 
Example 16
Project: Radium   Author: mehulj94   File: Mozilla.py    License: Apache License 2.0 6 votes vote down vote up
def save_db(self, userpath):

        # create the folder to save it by profile
        relative_path = constant.folder_name + os.sep + 'firefox'
        if not os.path.exists(relative_path):
            os.makedirs(relative_path)

        relative_path += os.sep + os.path.basename(userpath)
        if not os.path.exists(relative_path):
            os.makedirs(relative_path)

        # Get the database name
        if os.path.exists(userpath + os.sep + 'logins.json'):
            dbname = 'logins.json'
        elif os.path.exists(userpath + os.sep + 'signons.sqlite'):
            dbname = 'signons.sqlite'

        # copy the files (database + key3.db)
        try:
            ori_db = userpath + os.sep + dbname
            dst_db = relative_path + os.sep + dbname
            shutil.copyfile(ori_db, dst_db)
        except Exception, e:
            pass 
Example 17
Project: Radium   Author: mehulj94   File: cyberduck.py    License: Apache License 2.0 6 votes vote down vote up
def get_path(self):
        if 'APPDATA' in os.environ:
            directory = os.environ['APPDATA'] + '\Cyberduck'

            if os.path.exists(directory):
                for dir in os.listdir(directory):
                    if dir.startswith('Cyberduck'):
                        for d in os.listdir(directory + os.sep + dir):
                            path = directory + os.sep + dir + os.sep + d + os.sep + 'user.config'
                            if os.path.exists(path):
                                return path

                return 'User_profil_not_found'
            else:
                return 'CYBERDUCK_NOT_EXISTS'
        else:
            return 'APPDATA_NOT_FOUND'

    # parse the xml file 
Example 18
Project: dcc   Author: amimo   File: decompiler.py    License: Apache License 2.0 6 votes vote down vote up
def _find_class(self, clname, basefolder):
        # check if defpackage
        if "/" not in clname:
            # this is a defpackage class probably...
            # Search first for defpackage, then search for requested string
            res = self._find_class("defpackage/{}".format(clname), basefolder)
            if res:
                return res

        # We try to map inner classes here
        if "$" in clname:
            # sometimes the inner class get's an extra file, sometimes not...
            # So we try all possibilities
            for x in range(clname.count("$")):
                tokens = clname.split("$", x + 1)
                base = "$".join(tokens[:-1])
                res = self._find_class(base, basefolder)
                if res:
                    return res

        # Check the whole supplied name
        fname = os.path.join(basefolder, clname.replace("/", os.sep) + ".java")
        if not os.path.isfile(fname):
            return None
        return fname 
Example 19
Project: misp42splunk   Author: remg427   File: test_refactor.py    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_refactor_file_write_unchanged_file(self):
        test_file = os.path.join(FIXER_DIR, "parrot_example.py")
        debug_messages = []
        def recording_log_debug(msg, *args):
            debug_messages.append(msg % args)
        self.check_file_refactoring(test_file, fixers=(),
                                    options={"write_unchanged_files": True},
                                    mock_log_debug=recording_log_debug,
                                    actually_write=False)
        # Testing that it logged this message when write=False was passed is
        # sufficient to see that it did not bail early after "No changes".
        message_regex = r"Not writing changes to .*%s" % \
                re.escape(os.sep + os.path.basename(test_file))
        for message in debug_messages:
            if "Not writing changes" in message:
                self.assertRegex(message, message_regex)
                break
        else:
            self.fail("%r not matched in %r" % (message_regex, debug_messages)) 
Example 20
Project: vergeml   Author: mme   File: io.py    License: MIT License 5 votes vote down vote up
def normalize_filename(self, split, filename):
        """Return the filename without the parent samples directory
        """
        directory = self.samples_dir
        if split == 'val' and self.val_dir:
            directory = self.val_dir
        elif split == 'test' and self.test_dir:
            directory = self.test_dir

        return filename[len(directory):].strip(os.sep) 
Example 21
Project: cherrypy   Author: cherrypy   File: covercp.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def menu(self, base='/', pct='50', showpct='',
             exclude=r'python\d\.\d|test|tut\d|tutorial'):

        # The coverage module uses all-lower-case names.
        base = base.lower().rstrip(os.sep)

        yield TEMPLATE_MENU
        yield TEMPLATE_FORM % locals()

        # Start by showing links for parent paths
        yield "<div id='crumbs'>"
        path = ''
        atoms = base.split(os.sep)
        atoms.pop()
        for atom in atoms:
            path += atom + os.sep
            yield ("<a href='menu?base=%s&exclude=%s'>%s</a> %s"
                   % (path, urllib.parse.quote_plus(exclude), atom, os.sep))
        yield '</div>'

        yield "<div id='tree'>"

        # Then display the tree
        tree = get_tree(base, exclude, self.coverage)
        if not tree:
            yield '<p>No modules covered.</p>'
        else:
            for chunk in _show_branch(tree, base, '/', pct,
                                      showpct == 'checked', exclude,
                                      coverage=self.coverage):
                yield chunk

        yield '</div>'
        yield '</body></html>' 
Example 22
Project: MPContribs   Author: materialsproject   File: core.py    License: MIT License 5 votes vote down vote up
def __init__(cls, name, bases, d):
        """initialize Schema, decorators, definitions, and tags"""
        super(SwaggerViewType, cls).__init__(name, bases, d)

        if not __name__ == cls.__module__:
            # e.g.: cls.__module__ = mpcontribs.api.projects.views
            views_path = cls.__module__.split(".")
            doc_path = ".".join(views_path[:-1] + ["document"])
            cls.tags = [views_path[-2]]
            doc_filepath = doc_path.replace(".", os.sep) + ".py"
            if os.path.exists(doc_filepath):
                cls.doc_name = cls.tags[0].capitalize()
                Model = getattr(import_module(doc_path), cls.doc_name)
                cls.schema_name = cls.doc_name + "Schema"
                cls.Schema = type(
                    cls.schema_name,
                    (ModelSchema, object),
                    {
                        "Meta": type(
                            "Meta",
                            (object,),
                            dict(model=Model, ordered=True, model_build_obj=False),
                        )
                    },
                )
                cls.definitions = {cls.schema_name: cls.Schema}
                cls.resource.schema = cls.Schema

                # write flask-mongorest swagger specs
                for method in cls.methods:
                    spec = get_specs(cls, method, cls.tags[0])
                    if spec:
                        dir_path = os.path.join(SWAGGER["doc_dir"], cls.tags[0])
                        file_path = os.path.join(dir_path, method.__name__ + ".yml")
                        if not os.path.exists(file_path):
                            os.makedirs(dir_path, exist_ok=True)
                            with open(file_path, "w") as f:
                                yaml.dump(spec, f)
                                logger.warning(
                                    f"{cls.tags[0]}.{method.__name__} written to {file_path}"
                                ) 
Example 23
Project: MPContribs   Author: materialsproject   File: utils.py    License: MIT License 5 votes vote down vote up
def get_user_explorer_name(path, view="index"):
    return "_".join(os.path.dirname(os.path.normpath(path)).split(os.sep)[-4:] + [view]) 
Example 24
Project: MPContribs   Author: materialsproject   File: utils.py    License: MIT License 5 votes vote down vote up
def duplicate_check(f):
    existing_identifiers = {}

    def wrapper(*args, **kwargs):

        module = inspect.getmodule(f)
        module_split = module.__name__.split(".")[:-1]
        mod_path = os.sep.join(module_split)
        from mpcontribs.users_modules import get_user_rester

        Rester = get_user_rester(mod_path)

        test_site = kwargs.get("test_site", True)
        with Rester(test_site=test_site) as mpr:
            for doc in mpr.query_contributions(criteria=mpr.query):
                existing_identifiers[doc["identifier"]] = doc["_id"]

        try:
            f(*args, **kwargs)
        except StopIteration:
            print("not adding more contributions")

        mpfile = args[0]
        update = 0
        for identifier in mpfile.ids:
            if identifier in existing_identifiers:
                cid = existing_identifiers[identifier]
                mpfile.insert_top(identifier, "cid", cid)
                update += 1

        print(len(mpfile.ids), "contributions to submit.")
        if update > 0:
            print(update, "contributions to update.")

    wrapper.existing_identifiers = existing_identifiers
    return wrapper


# https://stackoverflow.com/a/55545369 
Example 25
Project: django-template   Author: liip   File: __init__.py    License: MIT License 5 votes vote down vote up
def import_env_vars(directory):
    """
    List the files present in the given directory and for each of them create an environment variable named after the
    file, and which value is the contents of the file.
    """
    env_vars = glob.glob(os.path.join(directory, "*"))

    for env_var in env_vars:
        with open(env_var, "r") as env_var_file:
            os.environ.setdefault(
                env_var.split(os.sep)[-1], env_var_file.read().strip()
            ) 
Example 26
Project: multibootusb   Author: mbusb   File: update_cfg_file.py    License: GNU General Public License v2.0 5 votes vote down vote up
def fullpath(self, subpath):
        p = self.setup_params
        return os.path.join(p.usb_mount, p.distro_path[1:],
                            subpath).replace('/', os.sep) 
Example 27
Project: multibootusb   Author: mbusb   File: distro.py    License: GNU General Public License v2.0 5 votes vote down vote up
def perform_strict_detections(iso_cfg_ext_dir, iso_file_list):

    def run_contains(filepath, keyword, cfg_dir=iso_cfg_ext_dir):
        fullpath = os.path.join(cfg_dir, filepath.replace('/', os.sep))
        if not os.path.exists(fullpath):
            return False
        try:
            with open(fullpath, 'rb') as f:
                data = f.read().lower()
                return keyword in data
        except (IOError, OSError):
            log("Failed to open %s" % fullpath)
            return False

    def contains(relataive_filepath, keyword):
        return partial(run_contains, relataive_filepath,
                       bytes(keyword.lower(),'us-ascii'))

    # contains(P, K) predicates that file P contains the specified
    # string K. The predicate get never asserted if P has not been
    # extracted into the staging area (iso_cfg_ext_dir).
    test_vector = [
        ('wifislax',   contains('boot/syslinux/menu/vesamenu.cfg',
                                'menu label Wifislax64 Live')),
        ('salix-live', contains('boot/menus/mainmenu.cfg',
                                'MENU LABEL SALIX LIVE')),
        ('grml',       contains('boot/isolinux/vesamenu.cfg',
                                'menu title  Grml - Live Linux'))
        ]
    for distro, predicate in test_vector:
        predicates = [predicate] if callable(predicate) else predicate
        if all(p() for p in predicates):
            return distro
    return None 
Example 28
Project: kw_condition   Author: coreanq   File: util.py    License: MIT License 5 votes vote down vote up
def save_log(contents, subject="None", folder=""):
    current_dir = os.getcwd()
    filePath = current_dir + os.sep + folder + os.sep + cur_month() + ".txt"
    openMode = ""
    if (os.path.isfile(filePath)):
        openMode = 'a'
    else:
        openMode = 'w'
    line = '[{0:<8}][{1:<10}] {2}\n'.format(cur_date_time(), subject, contents)

    with open(filePath, openMode, encoding='utf8') as f:
        f.write(line)
    pass 
Example 29
Project: fullrmc   Author: bachiraoun   File: Engine.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def __validate_frame_name(self, frame):
        assert isinstance(frame, basestring), LOGGER.error("Frame must be a string, '%s' is given instead"%frame)
        splitFrame = frame.split(os.sep)
        assert len(splitFrame) <=2, LOGGER.error("Frame must be 1 level deep or at most 2 levels deep if multiframe")
        if splitFrame[0] not in self.__frames:
            if len(splitFrame) ==1:
                raise Exception(LOGGER.error("Unkown frame name '%s'"%frame))
            else:
                raise Exception(LOGGER.error("Unkown multiframe '%s'"%splitFrame[0]))
        if self.__frames[splitFrame[0]] is not None and len(splitFrame)==2:
            assert splitFrame[1] in self.__frames[splitFrame[0]]['frames_name'], LOGGER.error("Unkown subframe '%s' of registered multiframe '%s'"%(splitFrame[1],splitFrame[0]))
        #return tuple(frame) 
Example 30
Project: fullrmc   Author: bachiraoun   File: Engine.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def delete_frame(self, frame):
        """
        Delete frame data from Engine as well as from repository .

        :Parameters:
            #. frame (string): The frame to delete.
        """
        isNormalFrame, isMultiframe, isSubframe = self.get_frame_category(frame)
        assert frame != self.__usedFrame, LOGGER.error("It's not allowed to delete the used frame '%s'. Change used frame using Engine.set_used_frame method and try again"%frame)
        if isMultiframe:
            _multi = self.usedFrame.split(os.sep)[0]
            assert frame != _multi, LOGGER.error("It's not allowed to delete multiframe '%s' of used frame '%s'. Change used frame using Engine.set_used_frame method and try again"%(_multi,self.usedFrame))
        if isNormalFrame:
            _f = [f for f in self.__frames if self.__frames[f] is None]
            assert len(_f)>=1, LOGGER.error("No traditional frames found. This shouldn't have happened. PLEASE REPORT")
            assert len(_f)>=2, LOGGER.error("It's not allowed to delete the last traditional frame in engine '%s'"%(_f[0],))
        if isSubframe:
            _name = frame.split(os.sep)[0]
            if len(self.__frames[_name]['frames_name']) == 1:
                LOGGER.usage("Deleting last subframe '%s' of multiframe '%s' has resulted in deleting the multiframe"%(frame, _name))
                frame         = _name
                isNormalFrame = False
                isSubframe    = False
                isMultiframe  = True
        # remove frame directory
        if self.__repository is not None:
            self.__repository.remove_directory(relativePath=frame, clean=True)
        # reset frames
        if isNormalFrame or isMultiframe:
            self.__frames.pop(frame)
        else:
            _multiframe, _subframe = frame.split(os.sep)
            self.__frames[_multiframe]['frames_name'] = [frm for frm in self.__frames[_multiframe]['frames_name'] if frm !=_subframe]
        # save frames
        if self.__repository is not None:
            self.__repository.update_file(value=self.__frames, relativePath='_Engine__frames')