⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 platform.py

📁 bittorrent source by python. please enjoy
💻 PY
📖 第 1 页 / 共 3 页
字号:
    DeleteRegKey(HKCR, r".torrent\Content Type")    # This line maks it so that BT sticks around as an option    # after installing some other default handler for torrent files    WriteRegStr(HKCR, r".torrent\OpenWithProgids", "bittorrent", "")    # this prevents user-preference from generating "Invalid Menu Handle" by looking for an app    # that no longer exists, and instead points it at us.    WriteRegStr(HKCU, r"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.torrent", "Application", EXENAME)    WriteRegStr(HKCR, r"Applications\${EXENAME}\shell", "", "open")    WriteRegStr(HKCR, r"Applications\${EXENAME}\shell\open\command", "", r'"$INSTDIR\${EXENAME}" "%1"')    # Add a mime type    WriteRegStr(HKCR, r"MIME\Database\Content Type\application/x-bittorrent", "Extension", ".torrent")    # Add a shell command to match the 'bittorrent' handler described above    WriteRegStr(HKCR, "bittorrent", "", "TORRENT File")    WriteRegBin(HKCR, "bittorrent", "EditFlags", edit_flags)    # make us the default handler for bittorrent://    WriteRegBin(HKCR, "bittorrent", "URL Protocol", chr(0x0))    WriteRegStr(HKCR, r"bittorrent\Content Type", "", "application/x-bittorrent")    WriteRegStr(HKCR, r"bittorrent\DefaultIcon", "", r"$INSTDIR\${EXENAME},0")    WriteRegStr(HKCR, r"bittorrent\shell", "", "open")##    ReadRegStr $R1 HKCR "bittorrent\shell\open\command" ""##    StrCmp $R1 "" continue####    WriteRegStr HKCR "bittorrent\shell\open\command" "backup" $R1####    continue:    WriteRegStr(HKCR, r"bittorrent\shell\open\command", "", r'"$INSTDIR\${EXENAME}" "%1"')    # Add a shell command to handle torrent:// stuff    WriteRegStr(HKCR, "torrent", "", "TORRENT File")    WriteRegBin(HKCR, "torrent", "EditFlags", edit_flags)    # make us the default handler for torrent://    WriteRegBin(HKCR, "torrent", "URL Protocol", chr(0x0))    WriteRegStr(HKCR, r"torrent\Content Type", "", "application/x-bittorrent")    WriteRegStr(HKCR, r"torrent\DefaultIcon", "", "$INSTDIR\${EXENAME},0")    WriteRegStr(HKCR, r"torrent\shell", "", "open")##    ReadRegStr $R1 HKCR "torrent\shell\open\command" ""##    WriteRegStr HKCR "torrent\shell\open\command" "backup" $R1    WriteRegStr(HKCR, r"torrent\shell\open\command", "", r'"$INSTDIR\${EXENAME}" "%1"')def btspawn(cmd, *args):    ext = ''    if is_frozen_exe:        ext = '.exe'    path = os.path.join(app_root, cmd+ext)    if not os.access(path, os.F_OK):        if os.access(path+'.py', os.F_OK):            path = path+'.py'    args = [path] + list(args) # $0    spawn(*args)def spawn(*args):    if os.name == 'nt':        # do proper argument quoting since exec/spawn on Windows doesn't        bargs = args        args = []        for a in bargs:            if not a.startswith("/"):                a.replace('"', '\"')                a = '"%s"' % a            args.append(a)        argstr = ' '.join(args[1:])        # use ShellExecute instead of spawn*() because we don't want        # handles (like the controlsocket) to be duplicated        win32api.ShellExecute(0, "open", args[0], argstr, None, 1) # 1 == SW_SHOW    else:        if os.access(args[0], os.X_OK):            forkback = os.fork()            if forkback == 0:                # BUG: stop IPC!                os.execl(args[0], *args)        else:            #BUG: what should we do here?            passdef get_language(name):    url = LOCALE_URL + name + ".tar.gz"    r = urllib.urlopen(url)    # urllib seems to ungzip for us    tarname = os.path.join(locale_root, name + ".tar")    f = file(tarname, 'wb')    f.write(r.read())    f.close()    tar = tarfile.open(tarname, "r")    for tarinfo in tar:        tar.extract(tarinfo, path=locale_root)    tar.close()##def smart_gettext_translation(domain, localedir, languages, fallback=False):##    try:##        t = gettext.translation(domain, localedir, languages=languages)##    except Exception, e:##        for lang in languages:##            try:##                get_language(lang)##            except Exception, e:##                #print "Failed on", lang, e##                pass##        t = gettext.translation(domain, localedir, languages=languages,##                                fallback=fallback)##    return tdef blocking_smart_gettext_and_install(domain, localedir, languages,                                       fallback=False, unicode=False):    try:        t = gettext.translation(domain, localedir, languages=languages,                                fallback=fallback)    except Exception, e:        # if we failed to find the language, fetch it from the web        running_count = 0        running_deferred = {}        # Get some reasonable defaults for arguments that were not supplied        if languages is None:            languages = []            for envar in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'):                val = os.environ.get(envar)                if val:                    languages = val.split(':')                    break            if 'C' not in languages:                languages.append('C')        # now normalize and expand the languages        nelangs = []        for lang in languages:            for nelang in gettext._expand_lang(lang):                if nelang not in nelangs:                    nelangs.append(nelang)        languages = nelangs        for lang in languages:            try:                get_language(lang)            except: #urllib.HTTPError:                pass        t = gettext.translation(domain, localedir,                                languages=languages,                                fallback=True)    t.install(unicode)def smart_gettext_and_install(domain, localedir, languages,                              fallback=False, unicode=False):    try:        t = gettext.translation(domain, localedir, languages=languages,                                fallback=fallback)    except Exception, e:        # if we failed to find the language, fetch it from the web async-style        running_count = 0        running_deferred = {}        # Get some reasonable defaults for arguments that were not supplied        if languages is None:            languages = []            for envar in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'):                val = os.environ.get(envar)                if val:                    languages = val.split(':')                    break            if 'C' not in languages:                languages.append('C')        # now normalize and expand the languages        nelangs = []        for lang in languages:            for nelang in gettext._expand_lang(lang):                if nelang not in nelangs:                    nelangs.append(nelang)        languages = nelangs        for lang in languages:            d = ThreadedDeferred(None, get_language, lang)            def translate_and_install(r, td=d):                running_deferred.pop(td)                # only let the last one try to install                if len(running_deferred) == 0:                    t = gettext.translation(domain, localedir,                                            languages=languages,                                            fallback=True)                    t.install(unicode)            def failed(e, tlang=lang, td=d):                if td in running_deferred:                    running_deferred.pop(td)                # don't raise an error, just continue untranslated                sys.stderr.write('Could not find translation for language "%s"\n' %                                 tlang)                #traceback.print_exc(e)            d.addCallback(translate_and_install)            d.addErrback(failed)            # accumulate all the deferreds first            running_deferred[d] = 1        # start them all, the last one finished will install the language        for d in running_deferred:            d.start()        return    # install it if we got it the first time    t.install(unicode)def _gettext_install(domain, localedir=None, languages=None, unicode=False):    # gettext on win32 does not use locale.getdefaultlocale() by default    # other os's will fall through and gettext.find() will do this task    if os_name == 'nt':        # this code is straight out of gettext.find()        if languages is None:            languages = []            for envar in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'):                val = os.environ.get(envar)                if val:                    languages = val.split(':')                    break            # this is the important addition - since win32 does not typically            # have any enironment variable set, append the default locale before 'C'            languages.append(locale.getdefaultlocale()[0])            if 'C' not in languages:                languages.append('C')    # we call the smart version, because anyone calling this needs it    # before they can continue. yes, we do block on network IO. there is no    # alternative (installing post-startup causes already loaded strings not    # to be re-loaded)    blocking_smart_gettext_and_install(domain, localedir,                                       languages=languages,                                       unicode=unicode)def language_path():    dot_dir = get_dot_dir()    lang_file_name = os.path.join(dot_dir, efs2(u'data'),                                           efs2(u'language'))    return lang_file_namedef read_language_file():    """Reads the language file.  The language file contains the       name of the selected language, not any translations."""    lang = None    if os.name == 'nt':        # this pulls user-preference language from the installer location        try:            regko = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, "Software\\BitTorrent")            lang_num = _winreg.QueryValueEx(regko, "Language")[0]            lang_num = int(lang_num)            lang = language.locale_sucks[lang_num]        except:            pass    else:        lang_file_name = language_path()        if os.access(lang_file_name, os.F_OK|os.R_OK):            mode = 'r'            if sys.version_info >= (2, 3):                mode = 'U'            lang_file = open(lang_file_name, mode)            lang_line = lang_file.readline()            lang_file.close()            if lang_line:                lang = ''                for i in lang_line[:5]:                    if not i.isalpha() and i != '_':                        break                    lang += i                if lang == '':                    lang = None    return langdef write_language_file(lang):    """Writes the language file.  The language file contains the       name of the selected language, not any translations."""    if lang != '': # system default        get_language(lang)    if os.name == 'nt':        regko = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, "Software\\BitTorrent")        if lang == '':            _winreg.DeleteValue(regko, "Language")        else:            lcid = None            # I want two-way dicts            for id, code in language.locale_sucks.iteritems():                if code.lower() == lang.lower():                    lcid = id                    break            if not lcid:                raise KeyError(lang)            _winreg.SetValueEx(regko, "Language", 0, _winreg.REG_SZ, str(lcid))    else:        lang_file_name = language_path()        lang_file = open(lang_file_name, 'w')        lang_file.write(lang)        lang_file.close()def install_translation(unicode=False):    languages = None    try:        lang = read_language_file()        if lang is not None:            languages = [lang, ]    except:        #pass        traceback.print_exc()    _gettext_install('bittorrent', locale_root, languages=languages, unicode=unicode)def write_pid_file(fname, errorfunc = None):    """Creates a pid file on platforms that typically create such files;       otherwise, this returns without doing anything.  The fname should       not include a path.  The file will be placed in the appropriate       platform-specific directory (/var/run in linux).       """    assert type(fname) == str    assert errorfunc == None or callable(errorfunc)    if os.name == 'nt': return    try:        pid_fname = os.path.join(efs2(u'/var/run'),fname)        file(pid_fname, 'w').write(str(os.getpid()))    except:        try:            pid_fname = os.path.join(efs2(u'/etc/tmp'),fname)        except:            if errorfunc:                errorfunc(_("Couldn't open pid file. Continuing without one."))            else:                pass  # just continue without reporting warning.desktop = Noneif os.name == 'nt':    desktop = get_shell_dir(shellcon.CSIDL_DESKTOPDIRECTORY)else:    homedir = get_home_dir()    if homedir == None :        desktop = '/tmp/'    else:        desktop = homedir        if os.name in ('mac', 'posix'):            tmp_desktop = os.path.join(homedir, efs2(u'Desktop'))            if os.access(tmp_desktop, os.R_OK|os.W_OK):                desktop = tmp_desktop + os.sep

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -