Some minor things that tend to speed up startup time
authorepage <eopage@byu.net>
Wed, 21 Oct 2009 03:45:22 +0000 (03:45 +0000)
committerepage <eopage@byu.net>
Wed, 21 Oct 2009 03:45:22 +0000 (03:45 +0000)
git-svn-id: file:///svnroot/gc-dialer/trunk@551 c39d3808-3fe2-4d86-a59f-b7f623ee9f21

src/dc_glade.py
src/gv_backend.py

index 66b057c..541c0cf 100755 (executable)
@@ -40,6 +40,7 @@ import gtk_toolbox
 
 
 _moduleLogger = logging.getLogger("dc_glade")
+PROFILE_STARTUP = False
 
 
 def getmtime_nothrow(path):
@@ -163,7 +164,7 @@ class Dialcentral(object):
 
                self._window.connect("destroy", self._on_close)
                self._window.set_default_size(800, 300)
-               self._window.show_all()
+               self._window.show()
 
                self._loginSink = gtk_toolbox.threaded_stage(
                        gtk_toolbox.comap(
@@ -172,9 +173,12 @@ class Dialcentral(object):
                        )
                )
 
-               backgroundSetup = threading.Thread(target=self._idle_setup)
-               backgroundSetup.setDaemon(True)
-               backgroundSetup.start()
+               if not PROFILE_STARTUP:
+                       backgroundSetup = threading.Thread(target=self._idle_setup)
+                       backgroundSetup.setDaemon(True)
+                       backgroundSetup.start()
+               else:
+                       self._idle_setup()
 
        def _idle_setup(self):
                """
@@ -362,7 +366,7 @@ class Dialcentral(object):
 
                        serviceId = self.NULL_BACKEND
                        loggedIn = False
-                       if not force:
+                       if not force and self._defaultBackendId != self.NULL_BACKEND:
                                with gtk_toolbox.gtk_lock():
                                        banner = hildonize.show_busy_banner_start(self._window, "Logging In...")
                                try:
@@ -496,7 +500,10 @@ class Dialcentral(object):
                @note UI Thread
                """
                try:
-                       self._defaultBackendId = config.getint(constants.__pretty_app_name__, "active")
+                       if not PROFILE_STARTUP:
+                               self._defaultBackendId = config.getint(constants.__pretty_app_name__, "active")
+                       else:
+                               self._defaultBackendId = self.NULL_BACKEND
                        blobs = (
                                config.get(constants.__pretty_app_name__, "bin_blob_%i" % i)
                                for i in xrange(len(self._credentials))
@@ -873,7 +880,8 @@ def run_dialpad():
        if hildonize.IS_HILDON_SUPPORTED:
                gtk.set_application_name(constants.__pretty_app_name__)
        handle = Dialcentral()
-       gtk.main()
+       if not PROFILE_STARTUP:
+               gtk.main()
 
 
 class DummyOptions(object):
index 3f28b29..0b3a0bd 100644 (file)
@@ -48,11 +48,11 @@ except ImportError:
 
 
 _moduleLogger = logging.getLogger("gvoice.dialer")
-_TRUE_REGEX = re.compile("true")
-_FALSE_REGEX = re.compile("false")
 
 
 def safe_eval(s):
+       _TRUE_REGEX = re.compile("true")
+       _FALSE_REGEX = re.compile("false")
        s = _TRUE_REGEX.sub("True", s)
        s = _FALSE_REGEX.sub("False", s)
        return eval(s, {}, {})
@@ -124,7 +124,47 @@ class GVDialer(object):
                self._callbackNumber = ""
                self._callbackNumbers = {}
 
-       _forwardURL = "https://www.google.com/voice/mobile/phones"
+               # Suprisingly, moving all of these from class to self sped up startup time
+
+               self._validateRe = re.compile("^[0-9]{10,}$")
+
+               self._forwardURL = "https://www.google.com/voice/mobile/phones"
+               self._tokenURL = "http://www.google.com/voice/m"
+               self._loginURL = "https://www.google.com/accounts/ServiceLoginAuth"
+               self._galxRe = re.compile(r"""<input.*?name="GALX".*?value="(.*?)".*?/>""", re.MULTILINE | re.DOTALL)
+               self._tokenRe = re.compile(r"""<input.*?name="_rnr_se".*?value="(.*?)"\s*/>""")
+               self._accountNumRe = re.compile(r"""<b class="ms\d">(.{14})</b></div>""")
+               self._callbackRe = re.compile(r"""\s+(.*?):\s*(.*?)<br\s*/>\s*$""", re.M)
+
+               self._gvDialingStrRe = re.compile("This may take a few seconds", re.M)
+               self._clicktocallURL = "https://www.google.com/voice/m/sendcall"
+               self._sendSmsURL = "https://www.google.com/voice/m/sendsms"
+
+               self._recentCallsURL = "https://www.google.com/voice/inbox/recent/"
+               self._placedCallsURL = "https://www.google.com/voice/inbox/recent/placed/"
+               self._receivedCallsURL = "https://www.google.com/voice/inbox/recent/received/"
+               self._missedCallsURL = "https://www.google.com/voice/inbox/recent/missed/"
+
+               self._contactsRe = re.compile(r"""<a href="/voice/m/contact/(\d+)">(.*?)</a>""", re.S)
+               self._contactsNextRe = re.compile(r""".*<a href="/voice/m/contacts(\?p=\d+)">Next.*?</a>""", re.S)
+               self._contactsURL = "https://www.google.com/voice/mobile/contacts"
+               self._contactDetailPhoneRe = re.compile(r"""<div.*?>([0-9+\-\(\) \t]+?)<span.*?>\((\w+)\)</span>""", re.S)
+               self._contactDetailURL = "https://www.google.com/voice/mobile/contact"
+
+               self._voicemailURL = "https://www.google.com/voice/inbox/recent/voicemail/"
+               self._smsURL = "https://www.google.com/voice/inbox/recent/sms/"
+               self._seperateVoicemailsRegex = re.compile(r"""^\s*<div id="(\w+)"\s* class=".*?gc-message.*?">""", re.MULTILINE | re.DOTALL)
+               self._exactVoicemailTimeRegex = re.compile(r"""<span class="gc-message-time">(.*?)</span>""", re.MULTILINE)
+               self._relativeVoicemailTimeRegex = re.compile(r"""<span class="gc-message-relative">(.*?)</span>""", re.MULTILINE)
+               self._voicemailNameRegex = re.compile(r"""<a class=.*?gc-message-name-link.*?>(.*?)</a>""", re.MULTILINE | re.DOTALL)
+               self._voicemailNumberRegex = re.compile(r"""<input type="hidden" class="gc-text gc-quickcall-ac" value="(.*?)"/>""", re.MULTILINE)
+               self._prettyVoicemailNumberRegex = re.compile(r"""<span class="gc-message-type">(.*?)</span>""", re.MULTILINE)
+               self._voicemailLocationRegex = re.compile(r"""<span class="gc-message-location">.*?<a.*?>(.*?)</a></span>""", re.MULTILINE)
+               self._messagesContactID = re.compile(r"""<a class=".*?gc-message-name-link.*?">.*?</a>\s*?<span .*?>(.*?)</span>""", re.MULTILINE)
+               self._voicemailMessageRegex = re.compile(r"""(<span id="\d+-\d+" class="gc-word-(.*?)">(.*?)</span>|<a .*? class="gc-message-mni">(.*?)</a>)""", re.MULTILINE)
+               self._smsFromRegex = re.compile(r"""<span class="gc-message-sms-from">(.*?)</span>""", re.MULTILINE | re.DOTALL)
+               self._smsTimeRegex = re.compile(r"""<span class="gc-message-sms-time">(.*?)</span>""", re.MULTILINE | re.DOTALL)
+               self._smsTextRegex = re.compile(r"""<span class="gc-message-sms-text">(.*?)</span>""", re.MULTILINE | re.DOTALL)
 
        def is_authed(self, force = False):
                """
@@ -146,10 +186,6 @@ class GVDialer(object):
                self._lastAuthed = time.time()
                return True
 
-       _tokenURL = "http://www.google.com/voice/m"
-       _loginURL = "https://www.google.com/accounts/ServiceLoginAuth"
-       _galxRe = re.compile(r"""<input.*?name="GALX".*?value="(.*?)".*?/>""", re.MULTILINE | re.DOTALL)
-
        def _get_token(self):
                try:
                        tokenPage = self._browser.download(self._tokenURL)
@@ -212,9 +248,6 @@ class GVDialer(object):
                self._browser.cookies.clear()
                self._browser.cookies.save()
 
-       _gvDialingStrRe = re.compile("This may take a few seconds", re.M)
-       _clicktocallURL = "https://www.google.com/voice/m/sendcall"
-
        def dial(self, number):
                """
                This is the main function responsible for initating the callback
@@ -239,8 +272,6 @@ class GVDialer(object):
 
                return True
 
-       _sendSmsURL = "https://www.google.com/voice/m/sendsms"
-
        def send_sms(self, number, message):
                number = self._send_validation(number)
                try:
@@ -261,8 +292,6 @@ class GVDialer(object):
 
                return True
 
-       _validateRe = re.compile("^[0-9]{10,}$")
-
        def is_valid_syntax(self, number):
                """
                @returns If This number be called ( syntax validation only )
@@ -298,11 +327,6 @@ class GVDialer(object):
                """
                return self._callbackNumber
 
-       _recentCallsURL = "https://www.google.com/voice/inbox/recent/"
-       _placedCallsURL = "https://www.google.com/voice/inbox/recent/placed/"
-       _receivedCallsURL = "https://www.google.com/voice/inbox/recent/received/"
-       _missedCallsURL = "https://www.google.com/voice/inbox/recent/missed/"
-
        def get_recent(self):
                """
                @returns Iterable of (personsName, phoneNumber, exact date, relative date, action)
@@ -324,10 +348,6 @@ class GVDialer(object):
                                recentCallData["action"] = action
                                yield recentCallData
 
-       _contactsRe = re.compile(r"""<a href="/voice/m/contact/(\d+)">(.*?)</a>""", re.S)
-       _contactsNextRe = re.compile(r""".*<a href="/voice/m/contacts(\?p=\d+)">Next.*?</a>""", re.S)
-       _contactsURL = "https://www.google.com/voice/mobile/contacts"
-
        def get_contacts(self):
                """
                @returns Iterable of (contact id, contact name)
@@ -350,9 +370,6 @@ class GVDialer(object):
                                newContactsPageUrl = self._contactsURL + next_match.group(1)
                                contactsPagesUrls.append(newContactsPageUrl)
 
-       _contactDetailPhoneRe = re.compile(r"""<div.*?>([0-9+\-\(\) \t]+?)<span.*?>\((\w+)\)</span>""", re.S)
-       _contactDetailURL = "https://www.google.com/voice/mobile/contact"
-
        def get_contact_details(self, contactId):
                """
                @returns Iterable of (Phone Type, Phone Number)
@@ -368,19 +385,6 @@ class GVDialer(object):
                        phoneType = saxutils.unescape(detail_match.group(2))
                        yield (phoneType, phoneNumber)
 
-       _voicemailURL = "https://www.google.com/voice/inbox/recent/voicemail/"
-       _smsURL = "https://www.google.com/voice/inbox/recent/sms/"
-
-       @staticmethod
-       def _merge_messages(parsedMessages, json):
-               for message in parsedMessages:
-                       id = message["id"]
-                       jsonItem = json["messages"][id]
-                       message["isRead"] = jsonItem["isRead"]
-                       message["isSpam"] = jsonItem["isSpam"]
-                       message["isTrash"] = jsonItem["isTrash"]
-                       yield message
-
        def get_messages(self):
                try:
                        voicemailPage = self._browser.download(self._voicemailURL)
@@ -440,10 +444,6 @@ class GVDialer(object):
                flatHtml = htmlElement.text
                return flatHtml
 
-       _tokenRe = re.compile(r"""<input.*?name="_rnr_se".*?value="(.*?)"\s*/>""")
-       _accountNumRe = re.compile(r"""<b class="ms\d">(.{14})</b></div>""")
-       _callbackRe = re.compile(r"""\s+(.*?):\s*(.*?)<br\s*/>\s*$""", re.M)
-
        def _grab_account_info(self, page):
                tokenGroup = self._tokenRe.search(page)
                if tokenGroup is None:
@@ -475,18 +475,6 @@ class GVDialer(object):
                        number = number[1:]
                return number
 
-       _seperateVoicemailsRegex = re.compile(r"""^\s*<div id="(\w+)"\s* class=".*?gc-message.*?">""", re.MULTILINE | re.DOTALL)
-       _exactVoicemailTimeRegex = re.compile(r"""<span class="gc-message-time">(.*?)</span>""", re.MULTILINE)
-       _relativeVoicemailTimeRegex = re.compile(r"""<span class="gc-message-relative">(.*?)</span>""", re.MULTILINE)
-       _voicemailNameRegex = re.compile(r"""<a class=.*?gc-message-name-link.*?>(.*?)</a>""", re.MULTILINE | re.DOTALL)
-       _voicemailNumberRegex = re.compile(r"""<input type="hidden" class="gc-text gc-quickcall-ac" value="(.*?)"/>""", re.MULTILINE)
-       _prettyVoicemailNumberRegex = re.compile(r"""<span class="gc-message-type">(.*?)</span>""", re.MULTILINE)
-       _voicemailLocationRegex = re.compile(r"""<span class="gc-message-location">.*?<a.*?>(.*?)</a></span>""", re.MULTILINE)
-       _messagesContactID = re.compile(r"""<a class=".*?gc-message-name-link.*?">.*?</a>\s*?<span .*?>(.*?)</span>""", re.MULTILINE)
-       #_voicemailMessageRegex = re.compile(r"""<span id="\d+-\d+" class="gc-word-(.*?)">(.*?)</span>""", re.MULTILINE)
-       #_voicemailMessageRegex = re.compile(r"""<a .*? class="gc-message-mni">(.*?)</a>""", re.MULTILINE)
-       _voicemailMessageRegex = re.compile(r"""(<span id="\d+-\d+" class="gc-word-(.*?)">(.*?)</span>|<a .*? class="gc-message-mni">(.*?)</a>)""", re.MULTILINE)
-
        @staticmethod
        def _interpret_voicemail_regex(group):
                quality, content, number = group.group(2), group.group(3), group.group(4)
@@ -552,10 +540,6 @@ class GVDialer(object):
                        voicemailData["messageParts"] = ((whoFrom, message, when), )
                        yield voicemailData
 
-       _smsFromRegex = re.compile(r"""<span class="gc-message-sms-from">(.*?)</span>""", re.MULTILINE | re.DOTALL)
-       _smsTimeRegex = re.compile(r"""<span class="gc-message-sms-time">(.*?)</span>""", re.MULTILINE | re.DOTALL)
-       _smsTextRegex = re.compile(r"""<span class="gc-message-sms-text">(.*?)</span>""", re.MULTILINE | re.DOTALL)
-
        def _parse_sms(self, smsHtml):
                splitSms = self._seperateVoicemailsRegex.split(smsHtml)
                for messageId, messageHtml in itergroup(splitSms[1:], 2):
@@ -599,6 +583,16 @@ class GVDialer(object):
        def _decorate_sms(self, parsedTexts):
                return parsedTexts
 
+       @staticmethod
+       def _merge_messages(parsedMessages, json):
+               for message in parsedMessages:
+                       id = message["id"]
+                       jsonItem = json["messages"][id]
+                       message["isRead"] = jsonItem["isRead"]
+                       message["isSpam"] = jsonItem["isSpam"]
+                       message["isTrash"] = jsonItem["isTrash"]
+                       yield message
+
 
 def set_sane_callback(backend):
        """
@@ -723,22 +717,6 @@ def test_backend(username, password):
        return backend
 
 
-_TEST_WEBPAGES = [
-       ("forward", GVDialer._forwardURL),
-       ("token", GVDialer._tokenURL),
-       ("login", GVDialer._loginURL),
-       ("contacts", GVDialer._contactsURL),
-
-       ("voicemail", GVDialer._voicemailURL),
-       ("sms", GVDialer._smsURL),
-
-       ("recent", GVDialer._recentCallsURL),
-       ("placed", GVDialer._placedCallsURL),
-       ("recieved", GVDialer._receivedCallsURL),
-       ("missed", GVDialer._missedCallsURL),
-]
-
-
 def grab_debug_info(username, password):
        cookieFile = os.path.join(".", "raw_cookies.txt")
        try:
@@ -749,6 +727,21 @@ def grab_debug_info(username, password):
        backend = GVDialer(cookieFile)
        browser = backend._browser
 
+       _TEST_WEBPAGES = [
+               ("forward", backend._forwardURL),
+               ("token", backend._tokenURL),
+               ("login", backend._loginURL),
+               ("contacts", backend._contactsURL),
+
+               ("voicemail", backend._voicemailURL),
+               ("sms", backend._smsURL),
+
+               ("recent", backend._recentCallsURL),
+               ("placed", backend._placedCallsURL),
+               ("recieved", backend._receivedCallsURL),
+               ("missed", backend._missedCallsURL),
+       ]
+
        # Get Pages
        print "Grabbing pre-login pages"
        for name, url in _TEST_WEBPAGES: