コード例 #1
0
ファイル: utils.py プロジェクト: cool-RR/Miro
def movie_data_program_info(movie_path, thumbnail_path):
    main_bundle = NSBundle.mainBundle()
    bundle_path = main_bundle.bundlePath()
    rsrc_path = main_bundle.resourcePath()
    script_path = os.path.join(rsrc_path, 'qt_extractor.py')
    options = main_bundle.infoDictionary().get('PyOptions')
    env = None
    if options['alias'] == 1:
        py_exe_path = os.path.join(os.path.dirname(main_bundle.executablePath()), 'python')
        env = {'PYTHONPATH': ':'.join(sys.path), 'MIRO_BUNDLE_PATH': main_bundle.bundlePath()}
    else:
        py_version = main_bundle.infoDictionary().get('PythonInfoDict').get('PythonShortVersion')
        py_exe_path = os.path.join(main_bundle.privateFrameworksPath(), "Python.framework", "Versions", py_version, "bin", 'python')
        env = {'PYTHONHOME': rsrc_path, 'MIRO_BUNDLE_PATH': main_bundle.bundlePath()}
    # XXX
    # Unicode kludge.  This wouldn't be a problem once we switch to Python 3.
    # Only need to do conversion on the py_exe_path and script_path - 
    # movie_path and thumbnail_path are Python 2 strings.
    py_exe_path = py_exe_path.encode('utf-8')
    script_path = script_path.encode('utf-8')
    # ... et tu, environment variables.
    for k in env.keys():
        try:
            check_b(env[k])
        except:
            env[k] = env[k].encode('utf-8')
    return ((py_exe_path, script_path, movie_path, thumbnail_path), env)
コード例 #2
0
ファイル: utils.py プロジェクト: jcooley/miro
def _get_cmd_line_and_env_for_script(script_name):
    """Get command line and env variables for a script.

    script_name must be located in the resources directory.

    Returns the tuple (cmd_line, env)
    """
    main_bundle = NSBundle.mainBundle()
    bundle_path = main_bundle.bundlePath()
    rsrc_path = main_bundle.resourcePath()
    script_path = os.path.join(rsrc_path, script_name)
    options = main_bundle.infoDictionary().get('PyOptions')
    env = None
    if options['alias'] == 1:
        py_exe_path = os.path.join(os.path.dirname(main_bundle.executablePath()), 'python')
        env = {'PYTHONPATH': ':'.join(sys.path), 'MIRO_BUNDLE_PATH': main_bundle.bundlePath()}
    else:
        py_version = main_bundle.infoDictionary().get('PythonInfoDict').get('PythonShortVersion')
        py_exe_path = os.path.join(main_bundle.privateFrameworksPath(), "Python.framework", "Versions", py_version, "bin", 'python')
        env = {'PYTHONHOME': rsrc_path, 'MIRO_BUNDLE_PATH': main_bundle.bundlePath()}
    # XXX
    # Unicode kludge.  This wouldn't be a problem once we switch to Python 3.
    # Only need to do conversion on the py_exe_path and script_path - 
    # movie_path and thumbnail_path are Python 2 strings.
    py_exe_path = py_exe_path.encode('utf-8')
    script_path = script_path.encode('utf-8')
    # ... et tu, environment variables.
    for k in env.keys():
        try:
            check_b(env[k])
        except:
            env[k] = env[k].encode('utf-8')
    return ((py_exe_path, script_path), env)
コード例 #3
0
ファイル: utils.py プロジェクト: codito/miro
def unicode_to_filename(filename, path=None):
    """Takes in a unicode string representation of a filename (NOT a
    file path) and creates a valid byte representation of it
    attempting to preserve extensions.

    .. Note::

       This is not guaranteed to give the same results every time it
       is run, nor is it guaranteed to reverse the results of
       filename_to_unicode.
    """
    check_u(filename)
    if path:
        check_b(path)
    else:
        path = os.getcwd()

    # keep this a little shorter than the max length, so we can
    # add a number to the end
    max_len = os.statvfs(path)[statvfs.F_NAMEMAX] - 5

    for mem in ("/", "\000", "\\", ":", "*", "?", "\"", "'",
                "<", ">", "|", "&", "\r", "\n"):
        filename = filename.replace(mem, "_")

    new_filename = encode_fn(filename)

    while len(new_filename) > max_len:
        filename = shorten_fn(filename)
        new_filename = encode_fn(filename)

    return new_filename
コード例 #4
0
def unicode_to_filename(filename, path=None):
    """Takes in a unicode string representation of a filename (NOT a
    file path) and creates a valid byte representation of it
    attempting to preserve extensions.

    .. Note::

       This is not guaranteed to give the same results every time it
       is run, nor is it guaranteed to reverse the results of
       filename_to_unicode.
    """
    check_u(filename)
    if path:
        check_b(path)
    else:
        path = os.getcwd()

    # keep this a little shorter than the max length, so we can
    # add a number to the end
    max_len = os.statvfs(path)[statvfs.F_NAMEMAX] - 5

    for mem in ("/", "\000", "\\", ":", "*", "?", "\"", "'", "<", ">", "|",
                "&", "\r", "\n"):
        filename = filename.replace(mem, "_")

    new_filename = encode_fn(filename)

    while len(new_filename) > max_len:
        filename = shorten_fn(filename)
        new_filename = encode_fn(filename)

    return new_filename
コード例 #5
0
    def test_check_b(self):
        util.check_b(None);
        util.check_b("abc");

        self.assertRaises(util.MiroUnicodeError, util.check_b, 42)
        self.assertRaises(util.MiroUnicodeError, util.check_b, [])
        self.assertRaises(util.MiroUnicodeError, util.check_b, ['1','2'])
        self.assertRaises(util.MiroUnicodeError, util.check_b, {})
        self.assertRaises(util.MiroUnicodeError, util.check_b, {'a': 1, 'b':2})
コード例 #6
0
ファイル: utils.py プロジェクト: codito/miro
def filename_to_unicode(filename, path=None):
    """Given a filename in raw bytes, return the unicode representation

    .. Note::

       This is not guaranteed to give the same results every time it
       is run, not is it guaranteed to reverse the results of
       unicode_to_filename.
    """
    if path:
        check_b(path)
    check_b(filename)
    try:
        return filename.decode(locale.getpreferredencoding())
    except UnicodeDecodeError:
        return filename.decode('ascii', 'replace')
コード例 #7
0
def filename_to_unicode(filename, path=None):
    """Given a filename in raw bytes, return the unicode representation

    .. Note::

       This is not guaranteed to give the same results every time it
       is run, not is it guaranteed to reverse the results of
       unicode_to_filename.
    """
    if path:
        check_b(path)
    check_b(filename)
    try:
        return filename.decode(locale.getpreferredencoding())
    except UnicodeDecodeError:
        return filename.decode('ascii', 'replace')
コード例 #8
0
ファイル: utils.py プロジェクト: kfatehi/miro
def _get_cmd_line_and_env_for_script(script_name):
    """Get command line and env variables for a script.

    script_name must be located in the resources directory.

    Returns the tuple (cmd_line, env)
    """
    main_bundle = NSBundle.mainBundle()
    bundle_path = main_bundle.bundlePath()
    rsrc_path = main_bundle.resourcePath()
    script_path = os.path.join(rsrc_path, script_name)
    options = main_bundle.infoDictionary().get('PyOptions')
    env = None
    if options['alias'] == 1:
        py_exe_path = os.path.join(
            os.path.dirname(main_bundle.executablePath()), 'python')
        env = {
            'PYTHONPATH': ':'.join(sys.path),
            'MIRO_BUNDLE_PATH': main_bundle.bundlePath()
        }
    else:
        py_version = main_bundle.infoDictionary().get('PythonInfoDict').get(
            'PythonShortVersion')
        py_exe_path = os.path.join(main_bundle.privateFrameworksPath(),
                                   "Python.framework", "Versions", py_version,
                                   "bin", 'python')
        env = {
            'PYTHONHOME': rsrc_path,
            'MIRO_BUNDLE_PATH': main_bundle.bundlePath()
        }
    # XXX
    # Unicode kludge.  This wouldn't be a problem once we switch to Python 3.
    # Only need to do conversion on the py_exe_path and script_path -
    # movie_path and thumbnail_path are Python 2 strings.
    py_exe_path = py_exe_path.encode('utf-8')
    script_path = script_path.encode('utf-8')
    # ... et tu, environment variables.
    for k in env.keys():
        try:
            check_b(env[k])
        except:
            env[k] = env[k].encode('utf-8')
    return ((py_exe_path, script_path), env)
コード例 #9
0
ファイル: utils.py プロジェクト: jcooley/miro
def unicode_to_filename(filename, path = None):
    check_u(filename)
    if path:
        check_b(path)
    else:
        path = os.getcwd()

    # Keep this a little shorter than the max length, so we can run
    # nextFilename
    MAX_LEN = os.statvfs(path)[statvfs.F_NAMEMAX]-5

    for mem in ("/", "\000", "\\", ":", "*", "?", "'", "\"", "<", ">", "|", "&", "\r", "\n"):
        filename = filename.replace(mem, "_")

    new_filename = filename.encode('utf-8','replace')
    while len(new_filename) > MAX_LEN:
        filename = shortenFilename(filename)
        new_filename = filename.encode('utf-8','replace')

    return new_filename
コード例 #10
0
ファイル: utils.py プロジェクト: kfatehi/miro
def unicode_to_filename(filename, path=None):
    check_u(filename)
    if path:
        check_b(path)
    else:
        path = os.getcwd()

    # Keep this a little shorter than the max length, so we can run
    # nextFilename
    MAX_LEN = os.statvfs(path)[statvfs.F_NAMEMAX] - 5

    for mem in ("/", "\000", "\\", ":", "*", "?", "'", "\"", "<", ">", "|",
                "&", "\r", "\n"):
        filename = filename.replace(mem, "_")

    new_filename = filename.encode('utf-8', 'replace')
    while len(new_filename) > MAX_LEN:
        filename = shortenFilename(filename)
        new_filename = filename.encode('utf-8', 'replace')

    return new_filename
コード例 #11
0
ファイル: utils.py プロジェクト: jcooley/miro
def filename_to_unicode(filename, path = None):
    if path:
        check_b(path)
    check_b(filename)
    return filename.decode('utf-8', 'replace')
コード例 #12
0
ファイル: utils.py プロジェクト: kfatehi/miro
def filename_to_unicode(filename, path=None):
    if path:
        check_b(path)
    check_b(filename)
    return filename.decode('utf-8', 'replace')
コード例 #13
0
ファイル: utils.py プロジェクト: kmshi/miro
def filename_to_unicode(filename, path=None):
    if path:
        check_b(path)
    check_b(filename)
    return filename.decode("utf-8", "replace")