Пример #1
0
def get_matching_jobs(request, check_permission=False, **kwargs):
    """
  Returns an array of jobs where the returned
  jobs are matched by the provided filter arguments.

  If a filter argument is in kwargs it will supersede the same argument
  in the request object.

  Filter arguments may be jobid, pools, user, tasks, text and state.

  Filter by user ownership if check_permission is set to true.
  """
    jobfunc = {
        "completed": (request.jt.completed_jobs, ThriftJobState.SUCCEEDED),
        # Succeeded and completed are synonyms here.
        "succeeded": (request.jt.completed_jobs, ThriftJobState.SUCCEEDED),
        "running": (request.jt.running_jobs, ThriftJobState.RUNNING),
        "failed": (request.jt.failed_jobs, ThriftJobState.FAILED),
        "killed": (request.jt.killed_jobs, ThriftJobState.KILLED),
        "all": (request.jt.all_jobs, None)
    }
    if 'state' in kwargs:
        selection = kwargs['state']
    else:
        selection = request.GET.get("state", "all")

    if 'retired' in kwargs:
        retired_arg = kwargs['retired']
    else:
        retired_arg = request.GET.get("retired", None)

    retired = coerce_bool(retired_arg)

    joblist = jobfunc[selection][0]().jobs

    if retired == True:
        joblist += request.jt.retired_jobs(jobfunc[selection][1]).jobs

    return [
        Job.from_thriftjob(request.jt, j)
        for j in _filter_jobs_by_req(joblist, request, **kwargs)
        if not check_permission or request.user.is_superuser
        or j.profile.user == request.user.username
    ]
Пример #2
0
def get_matching_jobs(request, check_permission=False, **kwargs):
    """
  Returns an array of jobs where the returned
  jobs are matched by the provided filter arguments.

  If a filter argument is in kwargs it will supersede the same argument
  in the request object.

  Filter arguments may be jobid, pools, user, tasks, text and state.

  Filter by user ownership if check_permission is set to true.
  """
    jobfunc = {
        "completed": (request.jt.completed_jobs, ThriftJobState.SUCCEEDED),
        # Succeeded and completed are synonyms here.
        "succeeded": (request.jt.completed_jobs, ThriftJobState.SUCCEEDED),
        "running": (request.jt.running_jobs, ThriftJobState.RUNNING),
        "failed": (request.jt.failed_jobs, ThriftJobState.FAILED),
        "killed": (request.jt.killed_jobs, ThriftJobState.KILLED),
        "all": (request.jt.all_jobs, None),
    }
    if "state" in kwargs:
        selection = kwargs["state"]
    else:
        selection = request.GET.get("state", "all")

    if "retired" in kwargs:
        retired_arg = kwargs["retired"]
    else:
        retired_arg = request.GET.get("retired", None)

    retired = coerce_bool(retired_arg)

    joblist = jobfunc[selection][0]().jobs

    if retired == True:
        joblist += request.jt.retired_jobs(jobfunc[selection][1]).jobs

    return [
        Job.from_thriftjob(request.jt, j)
        for j in _filter_jobs_by_req(joblist, request, **kwargs)
        if not check_permission or request.user.is_superuser or j.profile.user == request.user.username
    ]
Пример #3
0
def listdir_paged(request, path):
    """
    A paginated version of listdir.

    Query parameters:
      pagenum           - The page number to show. Defaults to 1.
      pagesize          - How many to show on a page. Defaults to 15.
      sortby=?          - Specify attribute to sort by. Accepts:
                            (type, name, atime, mtime, size, user, group)
                          Defaults to name.
      descending        - Specify a descending sort order.
                          Default to false.
      filter=?          - Specify a substring filter to search for in
                          the filename field.
    """
    if not request.fs.isdir(path):
        raise PopupException("Not a directory: %s" % (path,))

    pagenum = int(request.GET.get('pagenum', 1))
    pagesize = int(request.GET.get('pagesize', 30))

    home_dir_path = request.user.get_home_directory()
    breadcrumbs = parse_breadcrumbs(path)

    all_stats = request.fs.listdir_stats(path)


    # Filter first
    filter_str = request.GET.get('filter', None)
    if filter_str:
        filtered_stats = filter(lambda sb: filter_str in sb['name'], all_stats)
        all_stats = filtered_stats

    # Sort next
    sortby = request.GET.get('sortby', None)
    descending_param = request.GET.get('descending', None)
    if sortby is not None:
        if sortby not in ('type', 'name', 'atime', 'mtime', 'user', 'group', 'size'):
            logger.info("Invalid sort attribute '%s' for listdir." %
                        (sortby,))
        else:
            all_stats = sorted(all_stats,
                               key=operator.attrgetter(sortby),
                               reverse=coerce_bool(descending_param))


    # Do pagination
    page = paginator.Paginator(all_stats, pagesize).page(pagenum)
    shown_stats = page.object_list

    # Include parent dir always as second option, unless at filesystem root.
    if Hdfs.normpath(path) != posixpath.sep:
        parent_path = request.fs.join(path, "..")
        parent_stat = request.fs.stats(parent_path)
        # The 'path' field would be absolute, but we want its basename to be
        # actually '..' for display purposes. Encode it since _massage_stats expects byte strings.
        parent_stat['path'] = parent_path
        parent_stat['name'] = ".."
        shown_stats.insert(0, parent_stat)

    # Include same dir always as first option to see stats of the current folder
    current_stat = request.fs.stats(path)
    # The 'path' field would be absolute, but we want its basename to be
    # actually '.' for display purposes. Encode it since _massage_stats expects byte strings.
    current_stat['path'] = path
    current_stat['name'] = "."
    shown_stats.insert(0, current_stat)

    page.object_list = [ _massage_stats(request, s) for s in shown_stats ]


    data = {
        'path': path,
        'breadcrumbs': breadcrumbs,
        'current_request_path': request.path,
        'files': page.object_list,
        'page': _massage_page(page),
        'pagesize': pagesize,
        'home_directory': request.fs.isdir(home_dir_path) and home_dir_path or None,
        'sortby': sortby,
        'descending': descending_param,
        # The following should probably be deprecated
        'cwd_set': True,
        'file_filter': 'any',
        'current_dir_path': path,
        'is_fs_superuser': request.user.username == request.fs.superuser,
        'is_superuser': request.user.username == request.fs.superuser,
        'groups': request.user.username == request.fs.superuser and [str(x) for x in Group.objects.values_list('name', flat=True)] or [],
        'users': request.user.username == request.fs.superuser and [str(x) for x in User.objects.values_list('username', flat=True)] or [],
        'superuser': request.fs.superuser
    }
    return render('listdir.mako', request, data)