Exemplo n.º 1
0
def getUserAgent():
    """
    Construct a rfc spec'd UserAgent string from the platform and version information
    
    Examples:
        OS X Intel: Chandler/0.7.2.dev-r15512 (Macintosh; U; 10.4-Tiger; i386; en_US)
        OS X Intel: Chandler/0.7.2.dev-r15512 (Macintosh; U; 10.5-Leopard; i386; en_US)
        WinXP:      Chandler/0.7.2.dev-r15512 (Windows; U; 5.1-WinNT; i386; en_US)
        Linux:      Chandler/0.7.2.dev-r15513 (Linux; U; Ubuntu-7.04-feisty; i386; en_US)
    """
    platformID = getPlatformID()
    locale     = i18n.getLocale().replace(';()', '')
    osname     = getOSName().replace(';()', '')

    if platformID == 'win' or platformID == 'win-cygwin':
        platform = 'Windows'
        cpu      = 'i386'
    elif platformID == 'osx-intel':
        platform = 'Macintosh'
        cpu      = 'i386'
    elif platformID == 'osx-ppc':
        platform = 'Macintosh'
        cpu      = 'PPC'
    else:
        platform = 'Linux'
        cpu      = 'i386'

    return 'Chandler/%s (%s; U; %s; %s; %s)' % (version.version, platform, osname, cpu, locale)
Exemplo n.º 2
0
def getUserAgent():
    """
    Construct a rfc spec'd UserAgent string from the platform and version information
    
    Examples:
        OS X Intel: Chandler/0.7.2.dev-r15512 (Macintosh; U; 10.4-Tiger; i386; en_US)
        OS X Intel: Chandler/0.7.2.dev-r15512 (Macintosh; U; 10.5-Leopard; i386; en_US)
        WinXP:      Chandler/0.7.2.dev-r15512 (Windows; U; 5.1-WinNT; i386; en_US)
        Linux:      Chandler/0.7.2.dev-r15513 (Linux; U; Ubuntu-7.04-feisty; i386; en_US)
    """
    platformID = getPlatformID()
    locale = i18n.getLocale().replace(';()', '')
    osname = getOSName().replace(';()', '')

    if platformID == 'win' or platformID == 'win-cygwin':
        platform = 'Windows'
        cpu = 'i386'
    elif platformID == 'osx-intel':
        platform = 'Macintosh'
        cpu = 'i386'
    elif platformID == 'osx-ppc':
        platform = 'Macintosh'
        cpu = 'PPC'
    else:
        platform = 'Linux'
        cpu = 'i386'

    return 'Chandler/%s (%s; U; %s; %s; %s)' % (version.version, platform,
                                                osname, cpu, locale)
Exemplo n.º 3
0
def showLocalePickerDialog():
    win = LocalePickerDialog()

    win.CenterOnScreen()
    val = win.ShowModal()

    if val == wx.ID_OK:
        # Get the new locale and if it differs from
        # current locale restart Chandler
        currentLocale = getLocale()
        newLocale = win.GetValue()

        if newLocale != currentLocale:
            prefs = Utility.loadPrefs(Globals.options)

            if "options" not in prefs:
                prefs["options"] = {}

            prefs["options"]["locale"] = newLocale
            prefs.write()

            # The locale needs to be passed since
            # restart preserves the command line
            # options from the previous startup.
            # If the previous startup contained
            # a locale command line flag it
            # will override the value for the locale
            # just added to the prefs file and
            # Chandler will not switch the locale
            # as expected.
            wx.GetApp().restart(locale=newLocale)

    win.Destroy()
Exemplo n.º 4
0
def restart():
    try:
        import subprocess

        # argv[0] == Chandler.py
        args = sys.argv[1:]

        # We obviously want to avoid silently blowing the repository
        while '--create' in args:
            args.remove('--create')
        while '-c' in args:
            args.remove('-c')
        while '--reload' in args:
            args.remove('--reload')

        if wx.Platform == '__WXGTK__' and \
            Globals.options.locale is None:
            # Restarted Chandler fails to find locale, so
            # work around that issue by explicitly adding
            # locale option. See bug 6668 for more information.
            import i18n
            args.append('--locale=%s' % i18n.getLocale())
        elif sys.platform == 'darwin':
            # If you start Chandler using the .app bundle, the restarted
            # application fails to find display. Work around this by
            # switching to the way Chandler is started from the command
            # line. See bug 6681 for more information.
            cmdLineStart = sys.executable.rfind(
                '/Python.app/Contents/MacOS/python') > 0
            if not cmdLineStart:
                cwd = os.getcwd()  # .. Chandler.app/Contents/Resources
                p = '/Library/Frameworks/Python.framework/Versions/' + sys.version[:
                                                                                   3] + '/Resources/Python.app/Contents/MacOS/Python'
                # XXX There is no way to detect if the running python
                # XXX interpreter was compiled optimized or not.
                # XXX So we fudge. The assumption is that we would never
                # XXX have both debug and release bits installed in the
                # XXX exact same location.
                if os.path.isdir(os.path.join(cwd, 'release')):
                    sys.executable = cwd + '/release' + p
                else:
                    sys.executable = cwd + '/debug' + p

        # Ask the user for the (recovery) options
        if '--ask' not in args:
            args.append('--ask')

        if not os.path.basename(sys.executable).startswith('chandler'):
            args.insert(0, sys.argv[0])  # Python needs Chandler.py

        subprocess.Popen([sys.executable] + args)
    except:
        pass
Exemplo n.º 5
0
def restart():
    try:
        import subprocess
        
        # argv[0] == Chandler.py
        args = sys.argv[1:]
        
        # We obviously want to avoid silently blowing the repository
        while '--create' in args:
            args.remove('--create')
        while '-c' in args:
            args.remove('-c')
        while '--reload' in args:
            args.remove('--reload')
        
        if wx.Platform == '__WXGTK__' and \
            Globals.options.locale is None:
            # Restarted Chandler fails to find locale, so
            # work around that issue by explicitly adding
            # locale option. See bug 6668 for more information.
            import i18n
            args.append('--locale=%s' % i18n.getLocale())
        elif sys.platform == 'darwin':
            # If you start Chandler using the .app bundle, the restarted
            # application fails to find display. Work around this by
            # switching to the way Chandler is started from the command
            # line. See bug 6681 for more information.
            cmdLineStart = sys.executable.rfind('/Python.app/Contents/MacOS/python') > 0
            if not cmdLineStart:
                cwd = os.getcwd() # .. Chandler.app/Contents/Resources
                p = '/Library/Frameworks/Python.framework/Versions/' + sys.version[:3] + '/Resources/Python.app/Contents/MacOS/Python'
                # XXX There is no way to detect if the running python
                # XXX interpreter was compiled optimized or not.
                # XXX So we fudge. The assumption is that we would never
                # XXX have both debug and release bits installed in the
                # XXX exact same location.
                if os.path.isdir(os.path.join(cwd, 'release')):
                    sys.executable = cwd + '/release' + p
                else:
                    sys.executable = cwd + '/debug' + p

        # Ask the user for the (recovery) options
        if '--ask' not in args:
            args.append('--ask')
            
        if not os.path.basename(sys.executable).startswith('chandler'):
            args.insert(0, sys.argv[0]) # Python needs Chandler.py
            
        subprocess.Popen([sys.executable] + args)
    except:
        pass
Exemplo n.º 6
0
    def __init__(self):
        super(LocalePickerDialog, self).__init__(wx.GetApp().mainFrame, -1, u"", style=wx.DEFAULT_DIALOG_STYLE)
        self._locales = {}

        localeCodes = getAvailableChandlerLocales()
        icuLocales = Locale.getAvailableLocales()
        icuLocaleCodes = icuLocales.keys()
        langCodeAdded = {}
        linux = sys.platform.startswith("linux")

        for localeCode in localeCodes:
            langCode = stripCountryCode(localeCode)

            if linux and not hasWxLocale(langCode):
                # Not all WxPython translations are
                # installed by default on English
                # versions of Linux. Thus even
                # though there is a translation
                # egg available for Chandler, wx
                # will raise an error on Chandler
                # start up
                continue

            if hasCountryCode(localeCode) and not langCode in localeCodes:
                # There is no translation egg available for
                # the langCode (fallback). In this case, country variations
                # can not be made available to the user. This will
                # be rare if ever happen that say a "fr_CA" egg is
                # registered with Chandler but not an "fr" egg.
                self._locales[Locale(localeCode).getDisplayName()] = localeCode
                continue

            if not langCodeAdded.has_key(langCode):
                added = False

                for icuLocale in icuLocaleCodes:
                    if icuLocale.startswith(langCode):
                        self._locales[icuLocales[icuLocale].getDisplayName()] = icuLocale
                        added = True
                if added:
                    langCodeAdded[langCode] = True

        currentLocale = getLocale()
        currentLocaleName = Locale(currentLocale).getDisplayName()

        if currentLocale not in localeCodes:
            # Add the current locale to the locale selection list.
            # This case occurs when a user manual specifies a locale
            # on the command line or via prefs that does not have
            # a translation egg installed.
            self._locales[currentLocaleName] = currentLocale

        choices = self._locales.keys()
        choices.sort()

        # Now continue with the normal construction of the dialog
        # contents
        sizer = wx.BoxSizer(wx.VERTICAL)
        label = wx.StaticText(self, -1, _(u"Please select a language:"), size=(DIALOG_WIDTH, -1))
        label.Wrap(DIALOG_WIDTH)

        sizer.Add(label, 0, wx.ALIGN_CENTER | wx.ALL, 10)

        self._localeChoices = wx.Choice(self, -1, choices=choices, size=(DIALOG_WIDTH - 70, -1))

        sizer.Add(self._localeChoices, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 10)

        pos = self._localeChoices.FindString(currentLocaleName)

        if pos != wx.NOT_FOUND:
            self._localeChoices.SetSelection(pos)

        sizer.AddSpacer(10, 0)

        bsizer = wx.BoxSizer(wx.HORIZONTAL)

        # Load the wx.ICON_EXCLAMATION icon
        bmp = wx.ArtProvider.GetBitmap(wx.ART_WARNING, wx.ART_MESSAGE_BOX, (32, 32))
        icon = wx.StaticBitmap(self, -1, bmp)
        bsizer.Add(icon, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 5)

        note = wx.StaticText(self, -1, _(u"Switching languages will cause Chandler to automatically restart."))

        note.Wrap(DIALOG_WIDTH)

        bsizer.Add(note, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 5)
        sizer.Add(bsizer)

        sizer.AddSpacer(5, 0)

        box = wx.BoxSizer(wx.HORIZONTAL)
        btn = wx.Button(self, wx.ID_OK)
        btn.SetDefault()
        box.Add(btn, 0, wx.ALIGN_RIGHT | wx.ALL, 5)

        btn = wx.Button(self, wx.ID_CANCEL)
        box.Add(btn, 0, wx.ALIGN_RIGHT | wx.ALL, 5)

        sizer.Add(box, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 10)

        self.SetSizer(sizer)
        self.SetAutoLayout(True)
        sizer.Fit(self)