コード例 #1
0
	def do_it_once(self, app, args):
		status = 200
		status_details = None
		context_id = self._write_start_event(app, args)
		try:
			if not self._call_prescript(app, args):
				self.fatal('Running prescript of %s failed. Aborting...' % app)
				status = 0
			else:
				try:
					try:
						with package_lock():
							if args.dry_run:
								self.dry_run(app, args)
							else:
								self._do_it(app, args)
					except LockError:
						raise ParallelOperationInProgress()
				except (Abort, KeyboardInterrupt) as exc:
					msg = str(exc)
					if msg:
						self.fatal(msg)
					self.warn('Aborting...')
					if exc.__class__ is KeyboardInterrupt:
						status = 401
					else:
						status = exc.code
						status_details = exc.get_exc_details()
				except Exception as exc:
					status = 500
					status_details = repr(exc)
					raise
		except AppCenterError as exc:
			status = exc.code
			raise
		else:
			return status == 200
		finally:
			if args.dry_run:
				pass
			elif status == 0:
				pass
			else:
				if status == 200:
					self._write_success_event(app, context_id, args)
					self._call_action_hooks(
						"{data_dir}/{app_id}/local/hooks/"
						"{when}-{action}.d".format(
							data_dir=DATA_DIR,
							app_id=app.id,
							action=self.get_action_name(),
							when="post"
						)
					)
				else:
					self._write_fail_event(app, context_id, status, args)
				if status != 200:
					self._revert(app, args)
				self._send_information_on_app(app, status, status_details, args)
				self._register_installed_apps_in_ucr()
コード例 #2
0
 def locked(self):
     try:
         if self._working():
             raise LockError()
         with package_lock():
             yield
     except LockError:
         raise umcm.UMC_Error(_('Another package operation is in progress'))
コード例 #3
0
 def do_it(self, args):
     app = args.app
     status = 200
     status_details = None
     context_id = self._write_start_event(app, args)
     try:
         action = self.get_action_name()
         self.log('Going to %s %s (%s)' % (action, app.name, app.version))
         errors, warnings = app.check(action)
         can_continue = self._handle_errors(app, args, errors, True)
         can_continue = self._handle_errors(
             app, args, warnings, fatal=not can_continue) and can_continue
         if self.needs_credentials(
                 app) and not self.check_user_credentials(args):
             can_continue = False
         if not can_continue or not self._call_prescript(app, args):
             status = 0
             self.fatal('Unable to %s %s. Aborting...' % (action, app.id))
         else:
             try:
                 self._show_license(app, args)
                 self._show_pre_readme(app, args)
                 try:
                     try:
                         with package_lock():
                             if args.dry_run:
                                 self.dry_run(app, args)
                             else:
                                 self._do_it(app, args)
                     except LockError:
                         raise ParallelOperationInProgress()
                 except (Abort, KeyboardInterrupt) as exc:
                     msg = str(exc)
                     if msg:
                         self.fatal(msg)
                     self.warn('Aborting...')
                     if exc.__class__ is KeyboardInterrupt:
                         status = 401
                     else:
                         status = exc.code
                         status_details = exc.get_exc_details()
                 except Exception as exc:
                     status = 500
                     status_details = repr(exc)
                     raise
                 else:
                     try:
                         self._show_post_readme(app, args)
                     except Abort:
                         pass
             except Abort:
                 self.warn('Cancelled...')
                 status = 0
     except AppCenterError as exc:
         status = exc.code
         raise
     except Exception as e:
         status = 502
         status_details = (str(e))
         raise
     else:
         return status == 200
     finally:
         if args.dry_run:
             pass
         elif status == 0:
             pass
         else:
             if status == 200:
                 self._write_success_event(app, context_id, args)
                 self._call_action_hooks("{data_dir}/{app_id}/local/hooks/"
                                         "{when}-{action}.d".format(
                                             data_dir=DATA_DIR,
                                             app_id=app.id,
                                             action=self.get_action_name(),
                                             when="post"))
             else:
                 self._write_fail_event(app, context_id, status, args)
             if status != 200:
                 self._revert(app, args)
             if args.send_info:
                 try:
                     # do not send more than 500 char of status_details
                     if isinstance(status_details, basestring):
                         status_details = status_details[-5000:]
                     self._send_information(app, status, status_details)
                 except NetworkError:
                     self.log('Ignoring this error...')
             self._register_installed_apps_in_ucr()
             upgrade_search = get_action('upgrade-search')
             upgrade_search.call_safe(app=[app], update=False)
コード例 #4
0
 def do_it(self, args):
     app = args.app
     status = 200
     status_details = None
     try:
         action = self.get_action_name()
         self.log('Going to %s %s (%s)' % (action, app.name, app.version))
         errors, warnings = app.check(action)
         can_continue = self._handle_errors(app, args, errors, True)
         can_continue = self._handle_errors(
             app, args, warnings, fatal=not can_continue) and can_continue
         if not can_continue or not self._call_prescript(app, args):
             status = 0
             self.fatal('Unable to %s %s. Aborting...' % (action, app.id))
         else:
             try:
                 self._show_license(app, args)
                 self._show_pre_readme(app, args)
                 try:
                     try:
                         with package_lock():
                             if args.dry_run:
                                 self.dry_run(app, args)
                             else:
                                 self._do_it(app, args)
                     except LockError:
                         raise ParallelOperationInProgress()
                 except (Abort, KeyboardInterrupt) as exc:
                     msg = str(exc)
                     if msg:
                         self.fatal(msg)
                     self.warn('Aborting...')
                     if exc.__class__ is KeyboardInterrupt:
                         status = 401
                     else:
                         status = exc.code
                         status_details = exc.get_exc_details()
                 except Exception as exc:
                     status = 500
                     status_details = repr(exc)
                     raise
                 else:
                     try:
                         self._show_post_readme(app, args)
                     except Abort:
                         pass
             except Abort:
                 self.warn('Cancelled...')
                 status = 0
     except AppCenterError as exc:
         status = exc.code
         raise
     except Exception:
         raise
     else:
         return status == 200
     finally:
         if args.dry_run:
             pass
         elif status == 0:
             pass
         else:
             if status != 200:
                 self._revert(app, args)
             if args.send_info:
                 try:
                     self._send_information(app, status, status_details)
                 except NetworkError:
                     self.log('Ignoring this error...')
             self._register_installed_apps_in_ucr()
             upgrade_search = get_action('upgrade-search')
             upgrade_search.call_safe(app=[app], update=False)