~cprov/uci-engine/1335753-glance-creds

« back to all changes in this revision

Viewing changes to cli/ci_cli/ticket.py

  • Committer: Celso Providelo
  • Date: 2014-07-02 12:03:41 UTC
  • mfrom: (631.2.6 uci-engine)
  • Revision ID: celso.providelo@canonical.com-20140702120341-whw493h74owc3hdl
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    return open(filepath)
35
35
 
36
36
 
 
37
class MismatchSuitesError(Exception):
 
38
    """Raised when submitted packages target multiple series."""
 
39
 
 
40
 
 
41
class UnsupportedSeriesError(Exception):
 
42
    """Raised when package series isn't supported."""
 
43
 
 
44
 
 
45
class UnsupportedSuiteError(Exception):
 
46
    """Raised when package series isn't supported."""
 
47
 
 
48
 
37
49
class SourcePackageUploadError(Exception):
38
50
    """Raised where there is an error during the SPU."""
39
51
 
116
128
 
117
129
class SubTicket():
118
130
 
119
 
    def __init__(self, owner, ticket_id):
 
131
    def __init__(self, owner, ticket_id=None):
120
132
        self.owner = owner
121
 
        self.ticket_id = str(ticket_id)
 
133
        self.ticket_id = ticket_id
122
134
        self.sourcepackage = ''
123
135
        self.files = ''
124
136
        self.version = ''
125
137
 
126
138
        self.spu_uri = ''
127
139
        self.subticket_uri = ''
128
 
        self.ticket_uri = utils.TICKET_BASE + self.ticket_id + '/'
 
140
 
 
141
    @property
 
142
    def ticket_uri(self):
 
143
        if self.ticket_id:
 
144
            return utils.TICKET_BASE + str(self.ticket_id) + '/'
 
145
        return ''
129
146
 
130
147
    def _parse_changes(self, changes_filepath):
131
148
        log.info("Parsing %s..." % changes_filepath)
134
151
        log.info("Validating .changes file...")
135
152
        self.files = changes.process()
136
153
        self.version = changes.source_version
 
154
        self.suite = changes.suite
 
155
        self.series = self.suite.split("-")[0]
137
156
        self.sourcepackage = changes.source_package_name
138
157
        self.version = changes.source_version
139
 
        log.info("Done. %s_%s will be uploaded." % (self.sourcepackage,
140
 
                                                    self.version))
 
158
        log.info("%s_%s parsed and validated." % (self.sourcepackage,
 
159
                                                  self.version))
141
160
 
142
161
    def _process(self):
143
162
        self._create_spu()
207
226
        self.ticket_uri = ''
208
227
        self.uploads = []
209
228
        self.subtickets = {}
 
229
        self.suite = ''
210
230
 
211
231
    def _create_ticket(self, args):
212
232
        data = {
213
233
            "title": args.title,
214
234
            "owner": args.owner,
215
235
            "description": args.description,
 
236
            "series": self.suite.split("-")[0],
216
237
            "bug_id": args.bug,
217
238
            "added_binaries": args.add,
218
239
            "removed_binaries": args.remove,
237
258
              " Engine. Your ticket number is %s." % self.ticket_id)
238
259
 
239
260
    def add_new_ticket(self, args):
240
 
        ticket_id = self._create_ticket(args)
 
261
        suites = []
 
262
        subtickets = []
 
263
        # First, process all sources and validate the series.
241
264
        for source in args.sources:
242
 
            subticket = SubTicket(owner=args.owner, ticket_id=ticket_id)
 
265
            subticket = SubTicket(owner=args.owner)
243
266
            subticket._parse_changes(source)
 
267
            suites.append(subticket.suite)
 
268
            subtickets.append(subticket)
 
269
        suite = set(suites)
 
270
        if len(suite) > 1:
 
271
            raise MismatchSuitesError(
 
272
                "All submitted packages have to target the same suite. "
 
273
                "You submitted packages with suites: {}".format(
 
274
                    ", ".join(suites)))
 
275
        # After the series/suite is validated, create the ticket and the
 
276
        # subtickets.
 
277
        self.suite = suite.pop()
 
278
        ticket_id = self._create_ticket(args)
 
279
        for subticket in subtickets:
 
280
            subticket.ticket_id = ticket_id
244
281
            subticket._process()
245
282
            self.subtickets[subticket.sourcepackage] = subticket
246
283
        self._update_ticket()