Пример #1
0
    def do_full_pull(self, force=False):
        try:
            connection = httplib.HTTPConnection(self.target_host)
            connection.request("GET",
                               ("/api/wallets/%s/labels.json?auth_token=%s" %
                                (self.wallet_id, self.auth_token())), "",
                               {'Content-Type': 'application/json'})
            response = connection.getresponse()
            if response.reason == httplib.responses[httplib.NOT_FOUND]:
                return
            try:
                response = json.loads(response.read())
            except ValueError as e:
                return False

            if "error" in response:
                QMessageBox.warning(
                    None, _("Error"),
                    _("Could not sync labels: %s" % response["error"]))
                return False

            for label in response:
                decoded_key = self.decode(label["external_id"])
                decoded_label = self.decode(label["text"])
                if force or not self.wallet.labels.get(decoded_key):
                    self.wallet.labels[decoded_key] = decoded_label
            return True
        except socket.gaierror as e:
            print_error('Error connecting to service: %s ' % e)
            return False
Пример #2
0
    def do_full_push(self):
        try:
            bundle = {"labels": {}}
            for key, value in self.wallet.labels.iteritems():
                encoded = self.encode(key)
                bundle["labels"][encoded] = self.encode(value)

            params = json.dumps(bundle)
            connection = httplib.HTTPConnection(self.target_host)
            connection.request(
                "POST", ("/api/wallets/%s/labels/batch.json?auth_token=%s" %
                         (self.wallet_id, self.auth_token())), params,
                {'Content-Type': 'application/json'})

            response = connection.getresponse()
            if response.reason == httplib.responses[httplib.NOT_FOUND]:
                return
            try:
                response = json.loads(response.read())
            except ValueError as e:
                return False

            if "error" in response:
                QMessageBox.warning(
                    None, _("Error"),
                    _("Could not sync labels: %s" % response["error"]))
                return False

            return True
        except socket.gaierror as e:
            print_error('Error connecting to service: %s ' % e)
            return False
Пример #3
0
    def do_full_pull(self, force = False):
        try:
            connection = httplib.HTTPConnection(self.target_host)
            connection.request("GET", ("/api/wallets/%s/labels.json?auth_token=%s" % (self.wallet_id, self.auth_token())),"", {'Content-Type': 'application/json'})
            response = connection.getresponse()
            if response.reason == httplib.responses[httplib.NOT_FOUND]:
                return
            try:
                response = json.loads(response.read())
            except ValueError as e:
                return False

            if "error" in response:
                QMessageBox.warning(None, _("Error"),_("Could not sync labels: %s" % response["error"]))
                return False

            for label in response:
                 decoded_key = self.decode(label["external_id"]) 
                 decoded_label = self.decode(label["text"]) 
                 if force or not self.wallet.labels.get(decoded_key):
                     self.wallet.labels[decoded_key] = decoded_label 
            return True
        except socket.gaierror as e:
            print_error('Error connecting to service: %s ' %  e)
            return False
Пример #4
0
    def do_full_push(self):
        try:
            bundle = {"labels": {}}
            for key, value in self.wallet.labels.iteritems():
                encoded = self.encode(key)
                bundle["labels"][encoded] = self.encode(value)

            params = json.dumps(bundle)
            connection = httplib.HTTPConnection(self.target_host)
            connection.request("POST", ("/api/wallets/%s/labels/batch.json?auth_token=%s" % (self.wallet_id, self.auth_token())), params, {'Content-Type': 'application/json'})

            response = connection.getresponse()
            if response.reason == httplib.responses[httplib.NOT_FOUND]:
                return
            try:
                response = json.loads(response.read())
            except ValueError as e:
                return False

            if "error" in response:
                QMessageBox.warning(None, _("Error"),_("Could not sync labels: %s" % response["error"]))
                return False

            return True
        except socket.gaierror as e:
            print_error('Error connecting to service: %s ' %  e)
            return False
Пример #5
0
 def load_theme(self):
     """Load theme retrieved from wallet file."""
     try:
         theme_prefix, theme_path = self.themes[self.theme_name]
     except KeyError:
         util.print_error("Theme not found!", self.theme_name)
         return
     full_theme_path = "%s/%s/style.css" % (theme_prefix, theme_path)
     with open(full_theme_path) as style_file:
         qApp.setStyleSheet(style_file.read())
Пример #6
0
    def set_label(self, item,label, changed):
        if not changed:
            return 
        try:
            bundle = {"label": {"external_id": self.encode(item), "text": self.encode(label)}}
            params = json.dumps(bundle)
            connection = httplib.HTTPConnection(self.target_host)
            connection.request("POST", ("/api/wallets/%s/labels.json?auth_token=%s" % (self.wallet_id, self.auth_token())), params, {'Content-Type': 'application/json'})

            response = connection.getresponse()
            if response.reason == httplib.responses[httplib.NOT_FOUND]:
                return
            response = json.loads(response.read())
        except socket.gaierror as e:
            print_error('Error connecting to service: %s ' %  e)
            return False
Пример #7
0
    def set_label(self, item, label, changed):
        if not changed:
            return
        try:
            bundle = {
                "label": {
                    "external_id": self.encode(item),
                    "text": self.encode(label)
                }
            }
            params = json.dumps(bundle)
            connection = httplib.HTTPConnection(self.target_host)
            connection.request("POST",
                               ("/api/wallets/%s/labels.json?auth_token=%s" %
                                (self.wallet_id, self.auth_token())), params,
                               {'Content-Type': 'application/json'})

            response = connection.getresponse()
            if response.reason == httplib.responses[httplib.NOT_FOUND]:
                return
            response = json.loads(response.read())
        except socket.gaierror as e:
            print_error('Error connecting to service: %s ' % e)
            return False