~submarine/unity-scope-openclipart/trunk

« back to all changes in this revision

Viewing changes to src/unity_openclipart_daemon.py

  • Committer: Tarmac
  • Author(s): Facundo Batista
  • Date: 2013-10-29 12:47:08 UTC
  • mfrom: (30.1.1 add-logging)
  • Revision ID: tarmac-20131029124708-byciqzikgfgz3h4t
Add logging.

Approved by PS Jenkins bot, Guillermo Gonzalez.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# You should have received a copy of the GNU General Public License along
15
15
# with this program.  If not, see <http://www.gnu.org/licenses/>.
16
16
 
17
 
from gi.repository import Unity, UnityExtras
 
17
from gi.repository import Unity
18
18
from gi.repository import Gio, GLib
19
 
import urllib
 
19
 
20
20
import feedparser
21
21
import gettext
 
22
import logging
22
23
import shutil
 
24
import urllib
23
25
 
24
26
APP_NAME = 'unity-scope-openclipart'
25
27
LOCAL_PATH = '/usr/share/locale/'
58
60
      'field':Unity.SchemaFieldType.OPTIONAL}
59
61
EXTRA_METADATA = [m1, m2, m3]
60
62
 
 
63
logger = logging.getLogger("unity.scope.openclipart")
 
64
 
61
65
def search(search, filters):
62
 
    '''
63
 
    Any search method returning results as a list of tuples.
64
 
    Available tuple fields:
65
 
    uri (string)
66
 
    icon (string)
67
 
    title (string)
68
 
    comment (string)
69
 
    dnd_uri (string)
70
 
    mimetype (string)
71
 
    category (int)
72
 
    result_type (Unity ResultType)
73
 
    extras metadata fields (variant)
74
 
    '''
 
66
    """Do the search in OpenClipArt."""
75
67
    results = []
76
68
    if not search:
77
69
        return results
78
70
    search = urllib.parse.quote(search)
79
71
    uri = "%sapi/search/?query=%s" % (SEARCH_URI, search)
80
 
    print(uri)
 
72
    logger.debug("Request: %s", uri)
81
73
    try:
82
74
        feed = feedparser.parse(uri)
83
 
    except Exception as error:
84
 
        print(error)
 
75
    except Exception:
 
76
        logger.exception("Error while fetching data.")
85
77
        feed = None
86
78
    if not feed or not 'entries' in feed:
87
79
        return results
105
97
                            'published':published,
106
98
                            'author':f['author'],
107
99
                            'resource':resource})
108
 
        except Exception as error:
109
 
            print(error)
 
100
        except Exception:
 
101
            logger.exception("Error while building search response.")
110
102
    return results
111
103
 
112
104
 
145
137
                if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
146
138
                    i['dnd_uri'] = i['uri']
147
139
                result_set.add_result(**i)
148
 
        except Exception as error:
149
 
            print (error)
 
140
        except Exception:
 
141
            logger.exception("Error while running search.")
150
142
 
151
143
class Preview (Unity.ResultPreviewer):
152
144