Ejemplo n.º 1
0
def get_transformation_options(project_type=None):
    """
    Checking what transformation options are available in configuration file for
    giving type of project.
    :param project_type: String. Type of the project (i.e. subsection in project
                         configuration file.
    :return: List. List of tuples, first item in tuple is type to which this
             project type can be transformed, second item is type's
             description
    """
    config = project_config()
    options = []
    for name in config.keys():
        desc = config[name].get("description", None)
        options.append((name.lower(), desc if desc else name))

    if (not project_type) or (project_type not in config.keys()):
        return options

    trans = config[project_type].get("transform", None)
    if not trans:
        return options

    options_copy = options.copy()
    for option in options_copy:
        if option[0] not in trans:
            options.remove(option)
    return options
Ejemplo n.º 2
0
def is_project_renewable(project):
    """
    Check if project type has finish_dt option in config file and set
    is_renewable property True if finish_dt present or False otherwise. But
    if finish_notice_dt is in configuration file the code actually check if
    dt.now() is in between time interval finish_notice_dt - now - finish_dt
    :param project: Object. Project object
    :return: Object. Project object
    """
    cfg = project_config()
    finish = cfg[project.type].get("finish_dt", None)
    resource_end = project.resources.ttl
    if finish and (resource_end > finish):
        finish = resource_end
    pre_end = cfg[project.type].get("finish_notice_dt", None)
    if finish and pre_end:
        now = dt.now(timezone.utc)
        if pre_end < now < finish:
            project.is_renewable = True
        else:
            project.is_renewable = False
    elif finish and not pre_end:
        project.is_renewable = True
    else:
        project.is_renewable = False
    return project
Ejemplo n.º 3
0
def sanity_check():
    conf = project_config()
    projects = db.session.query(Project).all()
    suspend_expired_projects(projects)
    warn_expired_projects(projects, conf)
    suspend_overconsumed_projects(projects)
    warn_overconsumed_projects(projects)
    consumption_check(projects)
    return "Sanity check done"
Ejemplo n.º 4
0
def renew(project):
    config = project_config()
    project_type = project.type.lower()
    if project_type not in config.keys():
        error("Type %s is not found in config" % project_type)
        return None
    form = RenewForm()
    form.name = project.name
    end = config[project_type].get("finish_dt", None)
    if not end:
        error("Type %s has no end option and not renewable" % project_type)
        return None
    return form
Ejemplo n.º 5
0
def unprocessed():
    query = Register.query.filter_by(processed=False)
    if "admin" in g.permissions:
        return query.all()

    approve = []
    config = project_config()
    for type in config.keys():
        acl = config[type].get("acl", [])
        if current_user.login in acl:
            approve.append(type)
        elif set(acl).intersection(set(g.permissions)):
            approve.append(type)
    return query.filter(Register.type.in_(approve)).all()
Ejemplo n.º 6
0
def is_project_extendable(project):
    """
    Check if project type has evaluation_dt or extendable option in config file
    and set is_extendable property True if one of the options is present or
    False otherwise.
    :param project: Object. Project object
    :return: Object. Project object
    """
    cfg = project_config()
    eva = cfg[project.type].get("evaluation_dt", None)
    ext = cfg[project.type].get("extendable", False)
    if eva or ext:
        project.is_extendable = True
    else:
        project.is_extendable = False
    return project
Ejemplo n.º 7
0
 def verify(self):
     """
     Verify if record is exists and user or user's role has proper access
     rights.
     :return: Object. Register record
     """
     if not self.pending:
         raise ValueError("Register project record is not set!")
     if "admin" in g.permissions:
         return self.pending
     config = project_config()
     acl = config[self.pending.type].get("acl", [])
     user_allowed = current_user.login in acl
     role_allowed = set(acl).intersection(set(g.permissions))
     if (not user_allowed) and (not role_allowed):
         raise ValueError("Processing of new project record is not allowed")
     return self.pending
Ejemplo n.º 8
0
def extend(project):
    config = project_config()
    project_type = project.type.lower()
    if project_type not in config.keys():
        return  # TODO: Check what to return in this case
    form = ExtendForm()
    form.name = project.name
    end = config[project_type].get("finish_dt", None)
    if end:
        form.end_date = end
    evaluation_date = config[project_type].get("evaluation_dt", None)
    if evaluation_date:
        evaluation_date.sort()
        form.eval_date = evaluation_date[0]
    evaluation_notice = config[project_type].get("evaluation_notice_dt", None)
    if evaluation_notice:
        evaluation_notice.sort()
        form.eval_note = evaluation_notice[0]
    return form