~sylvain-pineau/launchpad-results/trend-reports-yui3

« back to all changes in this revision

Viewing changes to lib/lpresults/registry/models/pillar.py

  • Committer: Marc Tardif
  • Date: 2011-07-25 17:11:24 UTC
  • Revision ID: marc.tardif@canonical.com-20110725171124-0gg693yorqv2sxbf
Added script for importing submissions from Launchpad.

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
    def __parent__(self):
103
103
        return getUtility(IServiceRootResource)
104
104
 
105
 
    def create(self, owner, name):
106
 
        """See `IPillarSet`."""
107
 
        launchpad_pillar = getUtility(ILaunchpad).getPillar(owner, name)
108
 
        if launchpad_pillar is None:
109
 
            return None
110
 
 
111
 
        resource_type_link = launchpad_pillar["resource_type_link"]
112
 
        resource_type = urlparse(resource_type_link)[5]
113
 
        if resource_type == "distribution":
114
 
            series_link = launchpad_pillar["current_series_link"]
115
 
            series_name = basename(urlparse(series_link)[2])
116
 
            return self.createDistribution(owner, name, series_name)
117
 
        elif resource_type == "project":
118
 
            series_link = launchpad_pillar["development_focus_link"]
119
 
            series_name = basename(urlparse(series_link)[2])
120
 
            return self.createProject(owner, name, series_name)
121
 
        else:
122
 
            raise AssertionError("Unknown pillar type: %s" % name)
123
 
 
124
105
    def createDistribution(self, *args, **kwargs):
125
106
        """See `IPillarSet`."""
126
107
        return getUtility(IDistributionSet).create(*args, **kwargs)
134
115
        search_params = self.search_params_factory(name=name)
135
116
        return self.search(search_params).one()
136
117
 
 
118
    def retrieveByName(self, name):
 
119
        """See `IPillarSet`."""
 
120
        pillar = self.getByName(name)
 
121
        if pillar is None:
 
122
            launchpad_pillar = getUtility(ILaunchpad).getPillar(name)
 
123
            if launchpad_pillar is not None:
 
124
                resource_type_link = launchpad_pillar["resource_type_link"]
 
125
                resource_type = urlparse(resource_type_link)[5]
 
126
                if resource_type == "distribution":
 
127
                    series_link = launchpad_pillar["current_series_link"]
 
128
                    series_name = basename(urlparse(series_link)[2])
 
129
                    pillar = self.createDistribution(name, series_name)
 
130
                elif resource_type == "project":
 
131
                    series_link = launchpad_pillar["development_focus_link"]
 
132
                    series_name = basename(urlparse(series_link)[2])
 
133
                    pillar = self.createProject(name, series_name)
 
134
                else:
 
135
                    raise AssertionError("Unknown pillar type: %s" % name)
 
136
 
 
137
        return pillar
 
138
 
137
139
    def search(self, *args):
138
140
        if not args:
139
141
            search_params = self.search_params_factory()