示例#1
0
 def _entries(self):
     parser = self.ini_parser_class(self.path)
     maxsize = parser.getint('playlist', 'NumberOfEntries', None)
     for i in range(1, self.maxsize if maxsize is None else maxsize + 1):
         path = parser.get('playlist', 'File%d' % i, None)
         if not path:
             if maxsize:
                 continue
             break
         path = self.normalize_playable_path(path)
         if not path:
             continue
         yield self.playable_class(
             path=path,
             app=self.app,
             duration=parser.getint(
                 'playlist', 'Length%d' % i,
                 None
                 ),
             title=parser.get(
                 'playlist',
                 'Title%d' % i,
                 None
                 ),
             )
示例#2
0
 def _entries(self):
     parser = self.ini_parser_class(self.path)
     maxsize = parser.getint('playlist', 'NumberOfEntries', None)
     for i in range(1, self.maxsize if maxsize is None else maxsize + 1):
         path = parser.get('playlist', 'File%d' % i, None)
         if not path:
             if maxsize:
                 continue
             break
         path = self.normalize_playable_path(path)
         if not path:
             continue
         yield self.playable_class(
             path=path,
             app=self.app,
             duration=parser.getint(
                 'playlist', 'Length%d' % i,
                 None
                 ),
             title=parser.get(
                 'playlist',
                 'Title%d' % i,
                 None
                 ),
             )
 def iter_files(self):
     maxsize = self._parser.getint('playlist', 'NumberOfEntries', None)
     for i in range(self.maxsize if maxsize is None else maxsize):
         pf = self.playable_class(
             path=self.normalize_playable_path(
                 self._parser.get('playlist', 'File%d' % i, None)),
             duration=self._parser.getint('playlist', 'Length%d' % i, None),
             title=self._parser.get('playlist', 'Title%d' % i, None),
         )
         if pf.path:
             yield pf
         elif maxsize is None:
             break
示例#4
0
文件: file.py 项目: Glebk0/browsepy
def alternative_filename(filename, attempt=None):
    """
    Generates an alternative version of given filename.

    If an number attempt parameter is given, will be used on the alternative
    name, a random value will be used otherwise.

    :param filename: original filename
    :param attempt: optional attempt number, defaults to null
    :return: new filename
    :rtype: str or unicode
    """
    filename_parts = filename.rsplit(u".", 2)
    name = filename_parts[0]
    ext = "".join(u".%s" % ext for ext in filename_parts[1:])
    if attempt is None:
        choose = random.choice
        extra = u" %s" % "".join(choose(fs_safe_characters) for i in range(8))
    else:
        extra = u" (%d)" % attempt
    return u"%s%s%s" % (name, extra, ext)
示例#5
0
文件: file.py 项目: Glebk0/browsepy
    def choose_filename(self, filename, attempts=999):
        """
        Get a new filename which does not colide with any entry on directory,
        based on given filename.

        :param filename: base filename
        :type filename: str
        :param attempts: number of attempts, defaults to 999
        :type attempts: int
        :returns: filename
        :rtype: str

        :raises FilenameTooLong: when filesystem filename size limit is reached
        :raises PathTooLong: when OS or filesystem path size limit is reached
        """
        new_filename = filename
        for attempt in range(2, attempts + 1):
            if not self.contains(new_filename):
                break
            new_filename = alternative_filename(filename, attempt)
        else:
            while self.contains(new_filename):
                new_filename = alternative_filename(filename)

        limit = self.pathconf.get("PC_NAME_MAX", 0)
        if limit and limit < len(filename):
            raise FilenameTooLongError(path=self.path,
                                       filename=filename,
                                       limit=limit)

        abspath = os.path.join(self.path, filename)
        limit = self.pathconf.get("PC_PATH_MAX", 0)
        if limit and limit < len(abspath):
            raise PathTooLongError(path=abspath, limit=limit)

        return new_filename
示例#6
0
文件: file.py 项目: Glebk0/browsepy
    OutsideDirectoryBase,
    OutsideRemovableBase,
    PathTooLongError,
    FilenameTooLongError,
)

logger = logging.getLogger(__name__)
unicode_underscore = "_".decode("utf-8") if compat.PY_LEGACY else "_"
underscore_replace = "%s:underscore" % __name__
codecs.register_error(underscore_replace, lambda error:
                      (unicode_underscore, error.start + 1))
binary_units = ("B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB")
standard_units = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
common_path_separators = "\\/"
restricted_chars = "/\0"
nt_restricted_chars = '/\0\\<>:"|?*' + "".join(map(chr, range(1, 32)))
restricted_names = (".", "..", "::", "/", "\\")
nt_device_names = (("CON", "PRN", "AUX", "NUL") +
                   tuple(map("COM{}".format, range(1, 10))) +
                   tuple(map("LPT{}".format, range(1, 10))))
fs_safe_characters = string.ascii_uppercase + string.digits


class Node(object):
    """
    Abstract filesystem node class.

    This represents an unspecified entity with a filesystem's path suitable for
    being inherited by plugins.

    When inheriting, the following attributes should be overwritten in order