~kissiel/checkbox/fix-1593732-broken-continue

« back to all changes in this revision

Viewing changes to checkbox-touch/py/checkbox_touch.py

"automatic merge of lp:~sylvain-pineau/checkbox/converged_launchers_2/ by tarmac [r=kissiel][bug=][author=sylvain-pineau]"

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
from plainbox.impl.commands.inv_run import SilentUI
65
65
from plainbox.impl.result import JobResultBuilder
66
66
from plainbox.impl.session.assistant import SessionAssistant
 
67
from plainbox.impl.transport import get_all_transports
67
68
import plainbox
68
69
 
69
70
from embedded_providers import EmbeddedProvider1PlugInCollection
195
196
            configs.append(launcher_definition)
196
197
            self.launcher.read(configs)
197
198
            self.assistant.use_alternate_configuration(self.launcher)
 
199
            self._prepare_transports()
198
200
 
199
201
    def __repr__(self):
200
202
        return "app"
511
513
 
512
514
    @view
513
515
    def export_results(self, output_format, option_list):
514
 
        """Export results to file(s) in the user's 'Documents' directory.."""
 
516
        """Export results to file(s) in the user's 'Documents' directory."""
515
517
        self.assistant.finalize_session()
516
518
        dirname = self._get_user_directory_documents()
517
519
        return self.assistant.export_to_file(
548
550
            submission_options
549
551
        )
550
552
 
 
553
    def _prepare_transports(self):
 
554
        self._available_transports = get_all_transports()
 
555
        self.transports = dict()
 
556
 
 
557
    @view
 
558
    def get_certification_transport_config(self):
 
559
        """Returns the c3 (certification) transport configuration."""
 
560
        for report in self.launcher.stock_reports:
 
561
            self._prepare_stock_report(report)
 
562
        if 'c3' in self.launcher.transports:
 
563
            return self.launcher.transports['c3']
 
564
        elif 'c3-staging' in self.launcher.transports:
 
565
            return self.launcher.transports['c3-staging']
 
566
        return {}
 
567
 
 
568
    @view
 
569
    def export_results_with_launcher_settings(self):
 
570
        """
 
571
        Export results to file(s) in the user's 'Documents' directory.
 
572
        This method follows the launcher reports configuration.
 
573
        """
 
574
        self.assistant.finalize_session()
 
575
        for report in self.launcher.stock_reports:
 
576
            self._prepare_stock_report(report)
 
577
        # reports are stored in an ordinary dict(), so sorting them ensures
 
578
        # the same order of submitting them between runs.
 
579
        html_url = ""
 
580
        for name, params in sorted(self.launcher.reports.items()):
 
581
            exporter_id = self.launcher.exporters[params['exporter']]['unit']
 
582
            if self.launcher.transports[params['transport']]['type'] == 'file':
 
583
                path = self.launcher.transports[params['transport']]['path']
 
584
                cls = self._available_transports['file']
 
585
                self.transports[params['transport']] = cls(path)
 
586
                transport = self.transports[params['transport']]
 
587
                result = self.assistant.export_to_transport(
 
588
                    exporter_id, transport)
 
589
                if (
 
590
                    result and 'url' in result and
 
591
                    result['url'].endswith('html')
 
592
                ):
 
593
                    html_url = result['url']
 
594
        return html_url
 
595
 
 
596
    def _prepare_stock_report(self, report):
 
597
        # this is purposefully not using pythonic dict-keying for better
 
598
        # readability
 
599
        if not self.launcher.transports:
 
600
            self.launcher.transports = dict()
 
601
        if not self.launcher.exporters:
 
602
            self.launcher.exporters = dict()
 
603
        if not self.launcher.reports:
 
604
            self.launcher.reports = dict()
 
605
        if report == 'certification':
 
606
            self.launcher.exporters['hexr'] = {
 
607
                'unit': '2013.com.canonical.plainbox::hexr'}
 
608
            self.launcher.transports['c3'] = {
 
609
                'type': 'certification',
 
610
                'secure_id': self.launcher.transports.get('c3', {}).get(
 
611
                    'secure_id', None)}
 
612
            self.launcher.reports['upload to certification'] = {
 
613
                'transport': 'c3', 'exporter': 'hexr'}
 
614
        elif report == 'certification-staging':
 
615
            self.launcher.exporters['hexr'] = {
 
616
                'unit': '2013.com.canonical.plainbox::hexr'}
 
617
            self.launcher.transports['c3-staging'] = {
 
618
                'type': 'certification',
 
619
                'secure_id': self.launcher.transports.get('c3', {}).get(
 
620
                    'secure_id', None),
 
621
                'staging': 'yes'}
 
622
            self.launcher.reports['upload to certification-staging'] = {
 
623
                'transport': 'c3-staging', 'exporter': 'hexr'}
 
624
        elif report == 'submission_files':
 
625
            timestamp = datetime.datetime.utcnow().isoformat()
 
626
            base_dir = self._get_user_directory_documents()
 
627
            for exporter, file_ext in [('hexr', '.xml'), ('html', '.html'),
 
628
                                       ('xlsx', '.xlsx'), ('tar', '.tar.xz')]:
 
629
                path = os.path.join(base_dir, ''.join(
 
630
                    ['submission_', timestamp, file_ext]))
 
631
                self.launcher.transports['{}_file'.format(exporter)] = {
 
632
                    'type': 'file',
 
633
                    'path': path}
 
634
                self.launcher.exporters[exporter] = {
 
635
                    'unit': '2013.com.canonical.plainbox::{}'.format(exporter)}
 
636
                self.launcher.reports['2_{}_file'.format(exporter)] = {
 
637
                    'transport': '{}_file'.format(exporter),
 
638
                    'exporter': '{}'.format(exporter)
 
639
                }
 
640
 
551
641
    @view
552
642
    def drop_permissions(self, app_id, services):
553
643
        # TODO: use XDG once available