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)
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)
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
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})
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')
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)
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
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
def filename_to_unicode(filename, path = None): if path: check_b(path) check_b(filename) return filename.decode('utf-8', 'replace')
def filename_to_unicode(filename, path=None): if path: check_b(path) check_b(filename) return filename.decode('utf-8', 'replace')
def filename_to_unicode(filename, path=None): if path: check_b(path) check_b(filename) return filename.decode("utf-8", "replace")