Beispiel #1
0
 def action_unsign(self, ids):
     try:
         builds = get_query_for_ids(self.get_query(), self.model, ids).all()
         not_signed = []
         success = []
         failed = []
         for build in builds:
             filename = os.path.basename(build.path)
             with io.open(os.path.join(current_app.config['DATA_PATH'], build.path), 'rb+') as f:
                 spk = SPK(f)
                 if spk.signature is None:
                     not_signed.append(filename)
                     continue
                 try:
                     spk.unsign()
                     success.append(filename)
                 except Exception:
                     failed.append(filename)
         if failed:
             if len(failed) == 1:
                 flash('Failed to unsign build %s' % failed[0], 'error')
             else:
                 flash('Failed to unsign %d builds: %s' % (len(failed), ', '.join(failed)), 'error')
         if not_signed:
             if len(not_signed) == 1:
                 flash('Build %s not signed' % not_signed[0], 'info')
             else:
                 flash('%d builds not signed: %s' % (len(not_signed), ', '.join(not_signed)), 'info')
         if success:
             if len(success) == 1:
                 flash('Build %s successfully unsigned' % success[0])
             else:
                 flash('Successfully unsigned %d builds: %s' % (len(success), ', '.join(success)))
     except Exception as e:  # pragma: no cover
         flash('Failed to unsign builds. %s' % str(e), 'error')
Beispiel #2
0
    def merge(self, ids):

        if len(ids) > 2:
            flash("Only two devices can be merged at a time.")
            return

        query = get_query_for_ids(self.get_query(), self.model, ids)

        devices = query.order_by(Device.created_at).all()

        types = set(device.device_type for device in devices)
        sub_types = set(device.device_sub_type for device in devices)

        if len(types) > 1 or len(sub_types) > 1:
            flash("Devices of different types or different sub types can't be "
                  "automatically merged.")
            return

        old_device, new_device = query

        if new_device.area is None:
            new_device.area = old_device.area

        for new_device_series in new_device.device_series:

            old_device_series = DeviceSeries.query.filter(
                DeviceSeries.series_id == new_device_series.series_id,
                DeviceSeries.device_id == old_device.id,
            ).one()

            flash("%r - %r " % (new_device_series, old_device_series))

            flash("%r" % old_device_series.data_points)

        db.session.commit()
Beispiel #3
0
    def merge(self, ids):

        if len(ids) > 2:
            flash("Only two devices can be merged at a time.")
            return

        query = get_query_for_ids(self.get_query(), self.model, ids)

        devices = query.order_by(Device.created_at).all()

        types = set(device.device_type for device in devices)
        sub_types = set(device.device_sub_type for device in devices)

        if len(types) > 1 or len(sub_types) > 1:
            flash("Devices of different types or different sub types can't be "
                  "automatically merged.")
            return

        old_device, new_device = query

        if new_device.area is None:
            new_device.area = old_device.area

        for new_device_series in new_device.device_series:

            old_device_series = DeviceSeries.query.filter(
                DeviceSeries.series_id == new_device_series.series_id,
                DeviceSeries.device_id == old_device.id,
            ).one()

            flash("%r - %r " % (new_device_series, old_device_series))

            flash("%r" % old_device_series.data_points)

        db.session.commit()
Beispiel #4
0
    def handle_action(self, return_view=None):
        action = request.form.get('action')
        ids = request.form.getlist('rowid')
        page, sort, sort_desc, search, filters = self._get_action_extra_args()
        select_all = request.form.get('select-all', 0, type=int)
        select_page = request.form.get('select-page', 0, type=int)

        if select_all:
            count, query = self.get_list(None, sort, sort_desc, search, filters, False, nolimit=True)
        elif select_page:
            count, query = self.get_list(page, sort, sort_desc, search, filters, False)
        else:
            query = get_query_for_ids(self.get_query(), self.model, ids)

        handler = self._actions_data.get(action)

        if handler and self.is_action_allowed(action):
            response = handler[0](ids, query)

            if response is not None:
                return response

        if not return_view:
            url = url_for('.' + self._default_view)
        else:
            url = url_for('.' + return_view)

        return redirect(url)
Beispiel #5
0
 def action_activate(self, ids):
     try:
         users = get_query_for_ids(self.get_query(), self.model, ids).all()
         for user in users:
             user.active = True
         self.session.commit()
         flash('User was successfully activated.' if len(users) ==
               1 else '%d users were successfully activated.' % len(users))
     except Exception as e:  # pragma: no cover
         self.session.rollback()
         flash('Failed to activate users. %s' % str(e), 'error')
Beispiel #6
0
 def action_deactivate(self, ids):
     try:
         users = get_query_for_ids(self.get_query(), self.model, ids).all()
         for user in users:
             user.active = False
         self.session.commit()
         flash('User was successfully deactivated.' if len(users) == 1 else
               '%d users were successfully deactivated.' % len(users))
     except Exception as e:  # pragma: no cover
         self.session.rollback()
         flash('Failed to deactivate users. %s' % str(e), 'error')
Beispiel #7
0
 def action_deactivate(self, ids):
     try:
         builds = get_query_for_ids(self.get_query(), self.model, ids).all()
         for build in builds:
             build.active = False
         self.session.commit()
         flash('Build was successfully deactivated.' if len(builds) == 1 else
               '%d builds were successfully deactivated.' % len(builds))
     except Exception as e:  # pragma: no cover
         self.session.rollback()
         flash('Failed to deactivate builds. %s' % str(e), 'error')
Beispiel #8
0
 def action_deactivate(self, ids):
     try:
         builds = get_query_for_ids(self.get_query(), self.model, ids).all()
         for build in builds:
             build.active = False
         self.session.commit()
         flash('Build was successfully deactivated.' if len(builds) ==
               1 else '%d builds were successfully deactivated.' %
               len(builds))
     except Exception as e:  # pragma: no cover
         self.session.rollback()
         flash('Failed to deactivate builds. %s' % str(e), 'error')
Beispiel #9
0
 def action_refresh(self, ids):
     try:
         query = get_query_for_ids(self.get_query(), self.model, ids)
         for worker in query.all():
             self._update_worker(worker.uid)
         count = query.count()
         flash(ngettext('Record was successfully refreshed.',
                        '%(count)s records were successfully refreshed.',
                        count, count=count))
     except Exception as ex:
         flash(gettext('Failed to refresh records. %(error)s',
                       error=str(ex)), 'error')
Beispiel #10
0
 def action_deactivate(self, ids):
     try:
         versions = get_query_for_ids(self.get_query(), self.model, ids).all()
         for version in versions:
             for build in version.builds:
                 build.active = False
         self.session.commit()
         flash('Builds on version were successfully deactivated.' if len(versions) == 1 else
               'Builds have been successfully deactivated for %d versions.' % len(versions))
     except Exception as e:  # pragma: no cover
         self.session.rollback()
         flash('Failed to deactivate versions\' builds. %s' % str(e), 'error')
Beispiel #11
0
 def action_activate(self, ids):
     try:
         versions = get_query_for_ids(self.get_query(), self.model,
                                      ids).all()
         for version in versions:
             for build in version.builds:
                 build.active = True
         self.session.commit()
         flash('Builds on version were successfully activated.'
               if len(versions) == 1 else
               'Builds have been successfully activated for %d versions.' %
               len(versions))
     except Exception as e:  # pragma: no cover
         self.session.rollback()
         flash('Failed to activate versions\' builds. %s' % str(e), 'error')
Beispiel #12
0
 def action_refresh(self, ids):
     try:
         query = get_query_for_ids(self.get_query(), self.model, ids)
         for worker in query.all():
             self._update_worker(worker.uid)
         count = query.count()
         flash(
             ngettext('Record was successfully refreshed.',
                      '%(count)s records were successfully refreshed.',
                      count,
                      count=count))
     except Exception as ex:
         flash(
             gettext('Failed to refresh records. %(error)s', error=str(ex)),
             'error')
Beispiel #13
0
 def action_sign(self, ids):
     try:
         versions = get_query_for_ids(self.get_query(), self.model,
                                      ids).all()
         already_signed = []
         success = []
         failed = []
         for version in versions:
             for build in version.builds:
                 filename = os.path.basename(build.path)
                 with io.open(
                         os.path.join(current_app.config['DATA_PATH'],
                                      build.path), 'rb+') as f:
                     spk = SPK(f)
                     if spk.signature is not None:
                         already_signed.append(filename)
                         continue
                     try:
                         spk.sign(current_app.config['GNUPG_TIMESTAMP_URL'],
                                  current_app.config['GNUPG_PATH'])
                         success.append(filename)
                     except Exception:
                         failed.append(filename)
             if failed:
                 if len(failed) == 1:
                     flash('Failed to sign build %s' % failed[0], 'error')
                 else:
                     flash(
                         'Failed to sign %d builds: %s' %
                         (len(failed), ', '.join(failed)), 'error')
             if already_signed:
                 if len(already_signed) == 1:
                     flash('Build %s already signed' % already_signed[0],
                           'info')
                 else:
                     flash(
                         '%d builds already signed: %s' %
                         (len(already_signed), ', '.join(already_signed)),
                         'info')
             if success:
                 if len(success) == 1:
                     flash('Build %s successfully signed' % success[0])
                 else:
                     flash('Successfully signed %d builds: %s' %
                           (len(success), ', '.join(success)))
     except Exception as e:  # pragma: no cover
         flash('Failed to sign builds. %s' % str(e), 'error')
Beispiel #14
0
 def action_unsign(self, ids):
     try:
         builds = get_query_for_ids(self.get_query(), self.model, ids).all()
         not_signed = []
         success = []
         failed = []
         for build in builds:
             filename = os.path.basename(build.path)
             with io.open(
                     os.path.join(current_app.config['DATA_PATH'],
                                  build.path), 'rb+') as f:
                 spk = SPK(f)
                 if spk.signature is None:
                     not_signed.append(filename)
                     continue
                 try:
                     spk.unsign()
                     success.append(filename)
                 except Exception:
                     failed.append(filename)
         if failed:
             if len(failed) == 1:
                 flash('Failed to unsign build %s' % failed[0], 'error')
             else:
                 flash(
                     'Failed to unsign %d builds: %s' %
                     (len(failed), ', '.join(failed)), 'error')
         if not_signed:
             if len(not_signed) == 1:
                 flash('Build %s not signed' % not_signed[0], 'info')
             else:
                 flash(
                     '%d builds not signed: %s' %
                     (len(not_signed), ', '.join(not_signed)), 'info')
         if success:
             if len(success) == 1:
                 flash('Build %s successfully unsigned' % success[0])
             else:
                 flash('Successfully unsigned %d builds: %s' %
                       (len(success), ', '.join(success)))
     except Exception as e:  # pragma: no cover
         flash('Failed to unsign builds. %s' % str(e), 'error')
Beispiel #15
0
 def action_sign(self, ids):
     try:
         versions = get_query_for_ids(self.get_query(), self.model, ids).all()
         already_signed = []
         success = []
         failed = []
         for version in versions:
             for build in version.builds:
                 filename = os.path.basename(build.path)
                 with io.open(os.path.join(current_app.config['DATA_PATH'], build.path), 'rb+') as f:
                     spk = SPK(f)
                     if spk.signature is not None:
                         already_signed.append(filename)
                         continue
                     try:
                         spk.sign(current_app.config['GNUPG_TIMESTAMP_URL'], current_app.config['GNUPG_PATH'])
                         success.append(filename)
                     except Exception:
                         failed.append(filename)
             if failed:
                 if len(failed) == 1:
                     flash('Failed to sign build %s' % failed[0], 'error')
                 else:
                     flash('Failed to sign %d builds: %s' % (len(failed), ', '.join(failed)), 'error')
             if already_signed:
                 if len(already_signed) == 1:
                     flash('Build %s already signed' % already_signed[0], 'info')
                 else:
                     flash('%d builds already signed: %s' % (len(already_signed), ', '.join(already_signed)), 'info')
             if success:
                 if len(success) == 1:
                     flash('Build %s successfully signed' % success[0])
                 else:
                     flash('Successfully signed %d builds: %s' % (len(success), ', '.join(success)))
     except Exception as e:  # pragma: no cover
         flash('Failed to sign builds. %s' % str(e), 'error')
Beispiel #16
0
 def saltstack(self, ids):
     hosts = get_query_for_ids(self.get_query(), self.model, ids).all()
     return self.render('saltstack/action.html', hosts=hosts)