Esempio n. 1
0
 def resolve_type(self, type_id):
     key = "%s_issue_types_and_subtasks" % self.cache_prefix
     the_types = cache.get(key)
     the_types = None
     if the_types:
         try:
             the_types = pickle.loads(the_types)
         except pickle.UnpicklingError:
             the_types = None
     if the_types is None:
         self.logger.warn("Cache miss for %s" % key)
         the_types = self.service.getIssueTypes()
         the_types = [self.object_to_dict(t) for t in the_types]
         the_subtask_types = self.service.getSubTaskIssueTypes()
         the_subtask_types = [
             self.object_to_dict(st) for st in the_subtask_types
         ]
         the_types.extend(the_subtask_types)
         cache.set(key, pickle.dumps(the_types))
     the_type = [t for t in the_types if t['id'] == type_id]
     try:
         return the_type[0]
     except IndexError:
         type_help = ["%s -- %s" % (t['id'], t['name']) for t in the_types]
         self.logger.warn("Couldn't find type_id: %s in %s" %
                          (type_id, type_help))
         return {}
 def resolve_type(self, type_id):
     key = "%s_issue_types_and_subtasks" % self.cache_prefix
     the_types = cache.get(key)
     the_types = None
     if the_types:
         try:
             the_types = pickle.loads(the_types)
         except pickle.UnpicklingError:
             the_types = None
     if the_types == None:
         self.logger.warn("Cache miss for %s" % key)
         the_types = self.service.getIssueTypes()
         the_types = [self.object_to_dict(t) for t in the_types]
         the_subtask_types = self.service.getSubTaskIssueTypes()
         the_subtask_types = [self.object_to_dict(st) for st in the_subtask_types]
         the_types.extend(the_subtask_types)
         cache.set(key, pickle.dumps(the_types))
     the_type = [t for t in the_types if t['id'] == type_id]
     try:
         return the_type[0]
     except IndexError:
         type_help = ["%s -- %s" % (t['id'], t['name']) \
             for t in the_types]
         self.logger.warn("Couldn't find type_id: %s in %s" %
             (type_id, type_help))
         return {}
    def connect(self):
        auth_key = "offline_auth_%s" % self.cache_prefix
        auth = cache.get(auth_key)

        client = self.clients.get(self.wsdl_url, None)
        if not client:
            from suds.client import Client
            client = Client(self.wsdl_url)

            #We cache the client because there's
            #major overhead in instantiating
            #and the initial connection
            #and since this mostly is run
            #by a long running celeryd
            #process a simple in-memory
            #cache suffices
            self.clients[self.wsdl_url] = client

        if not auth:
            self.logger.warn("Cache miss for %s" % auth_key)
            auth = client.service.login(self.username, self.password)
            cache.set(auth_key, auth, 60 * 60)  # Cache for an hour

        self.auth = auth
        self._service = client.service
Esempio n. 4
0
    def connect(self):
        auth_key = "offline_auth_%s" % self.cache_prefix
        auth = cache.get(auth_key)

        client = self.clients.get(self.wsdl_url, None)
        if not client:
            from suds.client import Client
            client = Client(self.wsdl_url)

            #We cache the client because there's
            #major overhead in instantiating
            #and the initial connection
            #and since this mostly is run
            #by a long running celeryd
            #process a simple in-memory
            #cache suffices
            self.clients[self.wsdl_url] = client

        if not auth:
            self.logger.warn("Cache miss for %s" % auth_key)
            auth = client.service.login(self.username, self.password)
            cache.set(auth_key, auth, 60 * 60)  # Cache for an hour

        self.auth = auth
        self._service = client.service
Esempio n. 5
0
 def b64_image_src(self):
     from kardboard.app import cache
     image_src = cache.get(self.cache_key)
     if not image_src:
         b64_image_src = "data:image/png;base64,%s"
         r = requests.post(self.BASE_URL, data='&'.join(self.get_url_bits()))
         b64_image_src = b64_image_src % base64.b64encode(r.content)
         cache.set(self.cache_key, b64_image_src, 60 * 10)
         image_src = b64_image_src
     return image_src
 def resolve_status(self, status_id):
     key = "%s_statuses" % self.cache_prefix
     statuses = cache.get(key)
     if statuses:
         try:
             statuses = pickle.loads(statuses)
         except pickle.UnpicklingError:
             statuses = None
     if not statuses:
         self.logger.warn("Cache miss for %s" % key)
         statuses = self.service.getStatuses()
         statuses = [self.object_to_dict(s) for s in statuses]
         cache.set(key, pickle.dumps(statuses))
     status = [s for s in statuses if s.get('id') == status_id]
     try:
         return status[0]
     except IndexError:
         self.logger.warn("Couldn't find status_id: %s in %s" %
             (status_id, statuses))
         return {}
Esempio n. 7
0
 def resolve_resolution(self, resolution_id):
     key = "%s_resolutions" % self.cache_prefix
     resolutions = cache.get(key)
     if resolutions:
         try:
             resolutions = pickle.loads(resolutions)
         except pickle.UnpicklingError:
             resolutions = None
     if not resolutions:
         self.logger.warn("Cache miss for %s" % key)
         resolutions = self.service.getResolutions()
         resolutions = [self.object_to_dict(r) for r in resolutions]
         cache.set(key, pickle.dumps(resolutions))
     resolution = [r for r in resolutions if r.get('id') == resolution_id]
     try:
         return resolution[0]
     except IndexError:
         self.logger.warn("Couldn't find resolution_id: %s in %s" %
             (resolution_id, resolutions))
         return {}
Esempio n. 8
0
 def resolve_status(self, status_id):
     key = "%s_statuses" % self.cache_prefix
     statuses = cache.get(key)
     if statuses:
         try:
             statuses = pickle.loads(statuses)
         except pickle.UnpicklingError:
             statuses = None
     if not statuses:
         self.logger.warn("Cache miss for %s" % key)
         statuses = self.service.getStatuses()
         statuses = [self.object_to_dict(s) for s in statuses]
         cache.set(key, pickle.dumps(statuses))
     status = [s for s in statuses if s.get('id') == status_id]
     try:
         return status[0]
     except IndexError:
         self.logger.warn("Couldn't find status_id: %s in %s" %
                          (status_id, statuses))
         return {}
Esempio n. 9
0
 def resolve_resolution(self, resolution_id):
     key = "%s_resolutions" % self.cache_prefix
     resolutions = cache.get(key)
     if resolutions:
         try:
             resolutions = pickle.loads(resolutions)
         except pickle.UnpicklingError:
             resolutions = None
     if not resolutions:
         self.logger.warn("Cache miss for %s" % key)
         resolutions = self.service.getResolutions()
         resolutions = [self.object_to_dict(r) for r in resolutions]
         cache.set(key, pickle.dumps(resolutions))
     resolution = [r for r in resolutions if r.get('id') == resolution_id]
     try:
         return resolution[0]
     except IndexError:
         self.logger.warn("Couldn't find resolution_id: %s in %s" %
                          (resolution_id, resolutions))
         return {}