def validate(ctx):
    """Validates a scientific root specialization.

    :param DefinitionsValidationContext ctx: Validation contextual information.

    """
    # Set current module.
    ctx.module = ctx.root

    # Validate fields.
    for name, typeof in {
        ('AUTHORS', str),
        ('CONTACT', str),
        ('CONTRIBUTORS', str),
        ('CHANGE_HISTORY', list),
        ('DESCRIPTION', str),
        ('GRID', (str, type(None))),
        ('KEY_PROPERTIES', str),
        ('PROCESSES', list),
        }:
        validate_field(ctx, ctx.root, name, typeof)

    # Validate CHANGE_HISTORY.
    if [i for i in ctx.root.CHANGE_HISTORY if not isinstance(i, tuple) or len(i) != 4]:
        ctx.error("CHANGE_HISTORY entries must be 4 member tuples: (version, date, comment, who)")

    # Validate module keys.
    module_keys = [ctx.root.GRID, ctx.root.KEY_PROPERTIES] + ctx.root.PROCESSES
    module_keys = [i for i in module_keys if i is not None]
    for module_key in module_keys:
        if not ctx.has_module(module_key):
            ctx.error("{0} is an invalid key - no matching {0}.py file can be found".format(module_key))
Example #2
0
def _validate_fields(ctx, module):
    """Validates a module's standard attributes.

    """
    for field, typeof in {
        ('DESCRIPTION', str),
        ('DETAILS', collections.OrderedDict),
        ('ENUMERATIONS', collections.OrderedDict),
    }:
        utils.validate_field(ctx, module, field, typeof)
def _validate_fields(ctx, module):
    """Validates a module's standard attributes.

    """
    for field, typeof in {
        ('DESCRIPTION', str),
        ('DETAILS', collections.OrderedDict),
        ('ENUMERATIONS', collections.OrderedDict),
        }:
        utils.validate_field(ctx, module, field, typeof)
Example #4
0
def _validate_sections(ctx, module):
    """Validates a module's standard attributes.

    """
    for section in {'ENUMERATIONS', 'DETAILS'}:
        if utils.validate_field(ctx, module, section, collections.OrderedDict):
            _validate_section(ctx, module, section)
Example #5
0
def check_new_password1(request, password):
    errors = validate_field(password)
    if not errors:
        results = '<span class="alert alert-success">OK</span>'
    else:
        results = '<span class="alert alert-error">%s</span>' % errors
    return simplejson.dumps({'message': results})
def _validate_sections(ctx, module):
    """Validates a module's standard attributes.

    """
    for section in {'ENUMERATIONS', 'DETAILS'}:
        if utils.validate_field(ctx, module, section, collections.OrderedDict):
            _validate_section(ctx, module, section)
Example #7
0
def check_new_password2(request, password):
    password1 = password2 = None
    if 'new_password1' in password:
        password1 = password['new_password1']
    if 'new_password2' in password:
        password2 = password['new_password2']
    errors1 = validate_field(password1)
    errors2 = validate_field(password2)
    equal = password1 == password2
    if equal and not errors1 and not errors2:
        results = '<span class="alert alert-success">OK</span>'
    else:
        if not equal:
            errors2 += ('<span class="alert alert-error">%s</span>' %
                NOT_EQUAL_MSG)
        results = '<span class="alert alert-error">%s</span>' % errors2
    return simplejson.dumps({'message': results})
Example #8
0
def validate(ctx):
    """Validates a scientific root specialization.

    :param DefinitionsValidationContext ctx: Validation contextual information.

    """
    # Set current module.
    ctx.module = ctx.root

    # Validate fields.
    for name, typeof in {
        ('AUTHORS', str),
        ('CONTACT', str),
        ('CONTRIBUTORS', str),
        ('CHANGE_HISTORY', list),
        ('DESCRIPTION', str),
        ('GRID', (str, type(None))),
        ('KEY_PROPERTIES', str),
        ('PROCESSES', list),
    }:
        validate_field(ctx, ctx.root, name, typeof)

    # Validate CHANGE_HISTORY.
    if [
            i for i in ctx.root.CHANGE_HISTORY
            if not isinstance(i, tuple) or len(i) != 4
    ]:
        ctx.error(
            "CHANGE_HISTORY entries must be 4 member tuples: (version, date, comment, who)"
        )

    # Validate module keys.
    module_keys = [ctx.root.GRID, ctx.root.KEY_PROPERTIES] + ctx.root.PROCESSES
    module_keys = [i for i in module_keys if i is not None]
    for module_key in module_keys:
        if not ctx.has_module(module_key):
            ctx.error(
                "{0} is an invalid key - no matching {0}.py file can be found".
                format(module_key))
Example #9
0
    def get_degree(soup):
        """
        Get the last degree of the user whose profile page
        is being scraped.

        :param soup: BeautifulSoup object
        :return: degree: str
        """
        degree_tags = soup.find_all(class_="pv-entity__degree-name")
        if len(degree_tags) != 0:
            degree = degree_tags[0].get_text().split('\n')[2]
            degree = validate_field(degree)
        else:
            degree = ''
        return degree
Example #10
0
    def get_skills(self):
        """
        Get the skills of the user whose profile page is being scraped.
        Scroll down the page by sending the PAGE_DOWN button
        until either the "show more" button in the skills section
        has been found, or the end of the page has been reached
        Return a list of skills.

        :return: list: skills
        """
        skills = []
        button_found = False
        endofpage_reached = False
        attempt = 0
        max_attempts = 3
        delay = 3  # seconds
        body = self.driver.find_element_by_tag_name("body")
        last_height = self.driver.execute_script(
            "return document.body.scrollHeight")
        while not button_found:
            body.send_keys(Keys.PAGE_DOWN)
            sleep(2)
            new_height = self.driver.execute_script(
                "return document.body.scrollHeight")
            button_found, showmore_button = is_button_found(self.driver, delay)
            if button_found:
                self.driver.execute_script("arguments[0].click();",
                                           showmore_button)
                sleep(2)
                soup = bs(self.driver.page_source, 'html.parser')
                skills_tags = soup.find_all(
                    class_="pv-skill-category-entity__name-text")
                skills = [item.get_text(strip=True) for item in skills_tags]
                skills = [validate_field(skill) for skill in skills]
            if new_height == last_height:
                attempt += 1
                if attempt == max_attempts:
                    endofpage_reached = True
            else:
                last_height = new_height
            if button_found or endofpage_reached:
                break
        return skills