Beispiel #1
0
 def validate_allocations(self):
     if self.is_in_percentage:
         if self.total_allocation_percentage != 100:
             raise DomainException(message='Please ensure allocation percentages add up to 100')
     else:
         if self.total_allocation_amount != self.amount:
             raise DomainException(message='Please ensure allocation amounts add up to your total amount (%s)' % self.amount)
Beispiel #2
0
 def get_site_name(self):
     if not os.path.isfile('sitecopy.rc'):
         raise DomainException(message='Could not find a sitecopy config file "sitecopy.rc" in the current directory')
     with open('sitecopy.rc') as config_file:
         for line in config_file:
             match = re.match('.*(?!#).*site\s+(\S+)', line)
             if match:
                 return match.group(1)
     raise DomainException(message='Cannot find the site name in sitecopy.rc')
Beispiel #3
0
 def execute(self, args):
     super().execute(args)
     if os.path.exists(args.destination_directory):
         raise DomainException(message='The path %s already exists. Please move it out of the way first.' % args.destination_directory)
     try:
         os.mkdir(args.destination_directory)
     except Exception as ex:
         raise DomainException(message='Could not create %s: %s' % (args.destination_directory, str(ex)))
         
     for packaged_file in self.config.web.frontend_libraries.packaged_files():
         print('extracting %s' % packaged_file.full_path)
         shutil.copy(packaged_file.full_path, args.destination_directory)
Beispiel #4
0
 def assert_dialect(self, migration, *supported_dialects):
     dialect_name = self.engine.dialect.name
     if dialect_name not in supported_dialects:
         raise DomainException(
             message=
             'Migration %s does not support the database dialect you are running on (%s), only one of %s'
             % (migration, dialect_name, supported_dialects))
Beispiel #5
0
 def submit(self):
     if self.throws_exception:
         raise DomainException()
     for f in self.files:
         with f.open() as opened_file:
             contents = opened_file.read()
         self.submitted_file_info[f.filename] = (contents, f.mime_type)
     self.submitted = True
Beispiel #6
0
    def recalculate(self):
        if self.is_divide_by_zero:
            self.result = None
            raise DomainException(message='I can\'t divide by 0')

        if self.operator == 'plus':
            self.result = self.operand_a + self.operand_b
        elif self.operator == 'divide':
            self.result = int(self.operand_a / self.operand_b)
Beispiel #7
0
 def render(self, filename, render_format='svg'):
     try:
         from graphviz import Digraph
     except ImportError:
         raise DomainException(message='To use this, you have to install graphviz (pip install graphviz)')
     else:
         graph = Digraph()
         for node in self.graph.keys():
             graph.node(str(node))
         for node, deps in self.graph.items():
             for dep in deps:
                 graph.edge(str(node), str(dep))
         graph.render(filename, cleanup=True, format=render_format)
Beispiel #8
0
    def execute(self, args):
        super().execute(args)
        self.sitecopy = Executable('sitecopy')

        try:
            site_name = args.site_name or self.get_site_name()
            local_info_file = os.path.expanduser(os.path.join('~', '.sitecopy', site_name))
            if args.fetch_first or not os.path.exists(local_info_file):
                if os.path.exists(local_info_file):
                    os.remove(local_info_file)
                self.sitecopy.check_call('-r sitecopy.rc --fetch'.split()+[site_name])
            self.sitecopy.check_call('-r sitecopy.rc --update'.split()+[site_name])
        except subprocess.CalledProcessError as ex:
            raise DomainException(message='Running "%s" failed with exit code %s' % (' '.join(ex.cmd), ex.returncode))
Beispiel #9
0
 def send_mail(self, destination, subject_config_key, mail_config_key):
     data = self.get_data_for_substitution()
     config = ExecutionContext.get_context().config
     admin_email = config.accounts.admin_email
     subject = Template(
         config.get_from_string(subject_config_key)).safe_substitute(data)
     message_text = Template(
         config.get_from_string(mail_config_key)).safe_substitute(data)
     message = MailMessage(admin_email, [destination], subject,
                           message_text)
     mailer = config.accounts.mailer_class.from_context()
     try:
         mailer.send_message(message)
     except ConnectionError as e:
         message = _(
             'Could not send registration verification email message to %s: %s.'
         ) % (self.email, str(e))
         user_message = message + _(
             ' Please contact the site administrator and try again later.')
         logging.getLogger(__name__).error(message)
         raise DomainException(message=user_message)
Beispiel #10
0
 def __init__(self, account_status):
     DomainException.__init__(self, commit=False)
     self.account_status = account_status
 def always_break(self):
     raise DomainException('boo')
 def submit(self):
     raise DomainException(message='An exception happened on submit')
 def submit(self):
     if fixture.raise_domain_exception_on_submit:
         raise DomainException()
     fixture.submitted_model_object = self
Beispiel #14
0
 def change_something():
     fixture.changes_made = True
     if fixture.exception:
         raise DomainException('ex')
Beispiel #15
0
 def always_break(self):
     raise DomainException('designed to break')
Beispiel #16
0
 def handle_event(self):
     self.field_name = 1
     raise DomainException()
Beispiel #17
0
 def handle_event(self):
     if fixture.break_on_submit:
         raise DomainException()
Beispiel #18
0
 def callable_to_call():
     fixture.method_called += 1
     if fixture.exception:
         raise DomainException('ex')
Beispiel #19
0
def as_domain_exception(exception_to_translate):
    try:
        yield
    except exception_to_translate as e:
        raise DomainException(message=str(e))
Beispiel #20
0
 def change_something():
     fixture.changes_made = True
     if fixture.exception:
         raise DomainException(
             message='breaking intentionally',
             handled_inline=fixture.handle_inline)