Esempio n. 1
0
    def get(self, rule_id):
        rule = retry(db.rules.getRuleById, sleeptime=5, retry_exceptions=(SQLAlchemyError,),
                kwargs=dict(rule_id=rule_id))
        if not rule:
            return Response(status=404, response="Requested rule does not exist")

        releaseNames = retry(db.releases.getReleaseNames, sleeptime=5, retry_exceptions=(SQLAlchemyError,))

        form = EditRuleForm(prefix=str(rule_id), 
                throttle = rule['throttle'],  
                mapping = rule['mapping'], 
                priority = rule['priority'], 
                product = rule['product'],
                version = rule['version'],
                build_id = rule['buildID'],
                channel = rule['channel'],
                locale = rule['locale'],
                distribution = rule['distribution'],
                build_target = rule['buildTarget'],
                os_version = rule['osVersion'],
                dist_version = rule['distVersion'],
                comment = rule['comment'],
                update_type = rule['update_type'],
                header_arch = rule['headerArchitecture'],
                data_version=rule['data_version'])
        form.mapping.choices = [(item['name'],item['name']) for item in 
                releaseNames]
        form.mapping.choices.insert(0, ('', 'NULL' ) )

        return render_template('fragments/single_rule.html', rule=rule, form=form)
Esempio n. 2
0
    def _post(self, transaction, changed_by):
        # a Post here creates a new rule
        form = RuleForm()
        releaseNames = retry(db.releases.getReleaseNames, sleeptime=5, retry_exceptions=(SQLAlchemyError,))
        form.mapping.choices = [(item['name'],item['name']) for item in releaseNames]
        form.mapping.choices.insert(0, ('', 'NULL' ) )
        if not form.validate():
            self.log.debug(form.errors)
            return Response(status=400, response=form.errors)

        what = dict(throttle=form.throttle.data,   
                mapping=form.mapping.data,
                priority=form.priority.data,
                product = form.product.data,
                version = form.version.data,
                build_id = form.build_id.data,
                channel = form.channel.data,
                locale = form.locale.data,
                distribution = form.distribution.data,
                build_target = form.build_target.data,
                os_version = form.os_version.data,
                dist_version = form.dist_version.data,
                comment = form.comment.data,
                update_type = form.update_type.data,
                header_arch = form.header_arch.data)
        rule_id = retry(db.rules.addRule, sleeptime=5, retry_exceptions=(SQLAlchemyError,),
                kwargs=dict(changed_by=changed_by, what=what, transaction=transaction))
        return Response(status=200, response=rule_id)
Esempio n. 3
0
    def get(self):
        rules = db.rules.getOrderedRules()

        releaseNames = retry(db.releases.getReleaseNames, sleeptime=5, retry_exceptions=(SQLAlchemyError,))

        new_rule_form = RuleForm(prefix="new_rule");
        new_rule_form.mapping.choices = [(item['name'],item['name']) for item in 
                releaseNames]
        new_rule_form.mapping.choices.insert(0, ('', 'NULL' ))
        forms = {}

        for rule in rules:
            _id = rule['rule_id']
            self.log.debug(rule)
            forms[_id] = EditRuleForm(prefix=str(_id), 
                                    throttle = rule['throttle'],  
                                    mapping = rule['mapping'], 
                                    priority = rule['priority'], 
                                    product = rule['product'],
                                    version = rule['version'],
                                    build_id = rule['buildID'],
                                    channel = rule['channel'],
                                    locale = rule['locale'],
                                    distribution = rule['distribution'],
                                    build_target = rule['buildTarget'],
                                    os_version = rule['osVersion'],
                                    dist_version = rule['distVersion'],
                                    comment = rule['comment'],
                                    update_type = rule['update_type'],
                                    header_arch = rule['headerArchitecture'],
                                    data_version=rule['data_version'])
            forms[_id].mapping.choices = [(item['name'],item['name']) for item in 
                                                releaseNames]
            forms[_id].mapping.choices.insert(0, ('', 'NULL' ) )
        return render_template('rules.html', rules=rules, forms=forms, new_rule_form=new_rule_form)
Esempio n. 4
0
def compare_snippets(url1, url2, retries=3, timeout=10, diff=True):
    cfg = {'danger_mode': True}
    xml1 = retry(requests.get,
                 sleeptime=5,
                 attempts=retries,
                 args=(url1, ),
                 retry_exceptions=(requests.HTTPError,
                                   requests.ConnectionError),
                 kwargs={
                     'timeout': timeout,
                     'config': cfg
                 })
    xml1 = xml1.content.splitlines()
    xml2 = retry(requests.get,
                 sleeptime=5,
                 attempts=retries,
                 args=(url2, ),
                 retry_exceptions=(requests.HTTPError,
                                   requests.ConnectionError),
                 kwargs={
                     'timeout': timeout,
                     'config': cfg
                 })
    xml2 = xml2.content.splitlines()
    ret = [url1, xml1, url2, xml2]
    if xml1 != xml2:
        if diff:
            difflines = []
            for line in difflib.unified_diff(xml1,
                                             xml2,
                                             url1,
                                             url2,
                                             lineterm=""):
                difflines.append(line)
            ret.append(difflines)
        else:
            ret.append(True)
    else:
        ret.append(False)
    return ret
Esempio n. 5
0
def compare_snippets(url1, url2, retries=3, timeout=10, diff=True):
    cfg = {'danger_mode': True}
    xml1 = retry(requests.get, sleeptime=5, attempts=retries, args=(url1,),
                 retry_exceptions=(requests.HTTPError, requests.ConnectionError),
                 kwargs={'timeout': timeout, 'config': cfg})
    xml1 = xml1.content.splitlines()
    xml2 = retry(requests.get, sleeptime=5, attempts=retries, args=(url2,),
                 retry_exceptions=(requests.HTTPError, requests.ConnectionError),
                 kwargs={'timeout': timeout, 'config': cfg})
    xml2 = xml2.content.splitlines()
    ret = [url1, xml1, url2, xml2]
    if xml1 != xml2:
        if diff:
            difflines = []
            for line in difflib.unified_diff(xml1, xml2, url1, url2, lineterm=""):
                difflines.append(line)
            ret.append(difflines)
        else:
            ret.append(True)
    else:
        ret.append(False)
    return ret