~gary-lasker/software-center/new-apps

« back to all changes in this revision

Viewing changes to softwarecenter/db/update.py

  • Committer: Michael Vogt
  • Date: 2010-07-28 18:08:00 UTC
  • Revision ID: michael.vogt@ubuntu.com-20100728180800-ao1gg5x9my40k35s
  - fix crash in action buttons
* softwarecenter/db/update.py:
  - support additional metadata from Packages file for the
    "Whats new" repository (and possible others)

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
            for item in categories_str.split(";"):
64
64
                if item:
65
65
                    categories.append(item)
66
 
        except NoOptionError:
 
66
        except (NoOptionError, KeyError):
67
67
            pass
68
68
        return categories
69
69
    @property
70
70
    def desktopf(self):
71
71
        """ return the file that the AppInfo comes from """
72
72
 
 
73
class AptCachePkgParser(AppInfoParserBase):
 
74
    """ parser that fakes a Application from a pkg-record
 
75
        Useful for special repositories like "Whats New"
 
76
    """
 
77
 
 
78
    MAPPING = { 'Name'       : 'AppName',
 
79
              }
 
80
 
 
81
    # map from requested key to a static data element
 
82
    STATIC_DATA = { 'Type' : 'Application',
 
83
                  }
 
84
 
 
85
    def __init__(self, pkg):
 
86
        self.pkg = pkg
 
87
        self.origin = "apt-cache"
 
88
    def _apply_mapping(self, key):
 
89
        if key.startswith("X-AppInstall-"):
 
90
            key = key[len("X-AppInstall-"):]
 
91
        if key in self.MAPPING:
 
92
            return self.MAPPING[key]
 
93
        return key
 
94
    def get_desktop(self, key):
 
95
        key = self._apply_mapping(key)
 
96
        # check static data
 
97
        if key in self.STATIC_DATA:
 
98
            return self.STATIC_DATA[key]
 
99
        # we always excpect a AppName, if there is none, fake one
 
100
        if key == "AppName" and not "AppName" in self.pkg.candidate.record:
 
101
            return self.pkg.name
 
102
        return self.pkg.candidate.record[key]
 
103
    def has_option_desktop(self, key):
 
104
        # strip away bogus prefixes
 
105
        if key.startswith("X-AppInstall-"):
 
106
            key = key[len("X-AppInstall-"):]
 
107
        if key in self.STATIC_DATA:
 
108
            return True
 
109
        return self._apply_mapping(key) in self.pkg.candidate.record
 
110
    @property
 
111
    def desktopf(self):
 
112
        return self.origin
 
113
 
73
114
class DesktopTagSectionParser(AppInfoParserBase):
74
115
    def __init__(self, tag_section, tagfile):
75
116
        self.tag_section = tag_section
166
207
def update(db, cache, datadir=APP_INSTALL_PATH):
167
208
    update_from_app_install_data(db, cache, datadir)
168
209
    update_from_var_lib_apt_lists(db, cache)
 
210
    update_from_apt_cache_for_whats_new_repo(db, cache)
169
211
    # add db global meta-data
170
212
    logger.debug("adding popcon_max_desktop '%s'" % popcon_max)
171
213
    db.set_metadata("popcon_max_desktop", xapian.sortable_serialise(float(popcon_max)))
172
214
 
 
215
def update_from_apt_cache_for_whats_new_repo(db, cache):
 
216
 
 
217
    SPECIAL_ORIGINS_THAT_ARE_CONSIDERED_APPS = (
 
218
        "Application Review Board PPA",
 
219
        )
 
220
 
 
221
    for pkg in cache:
 
222
        if not pkg.candidate:
 
223
            continue
 
224
        for origin in pkg.candidate.origins:
 
225
            # FIXME: make this configuration
 
226
            if (origin.label in SPECIAL_ORIGINS_THAT_ARE_CONSIDERED_APPS and
 
227
                origin.trusted):
 
228
                parser = AptCachePkgParser(pkg)
 
229
                index_app_info_from_parser(parser, db, cache)
 
230
 
173
231
def update_from_var_lib_apt_lists(db, cache, listsdir=None):
174
232
    """ index the files in /var/lib/apt/lists/*AppInfo """
175
233
    if not listsdir: