Example #1
0
def create_platform_requests(request_group, platform, browser_form,
                             priority=0):
    """
    Create screenshots requests for selected browsers on one platform.
    """
    platform_lower = platform.name.lower().replace(' ', '-')
    for name in browser_form.fields:
        if not browser_form.cleaned_data[name]:
            continue # Browser not selected
        first_part, browser_name, major, minor = name.split('_')
        if first_part != platform_lower:
            continue # Different platform
        browser_group = BrowserGroup.objects.get(name__iexact=browser_name)
        Request.objects.get_or_create(
            request_group=request_group,
            platform=platform,
            browser_group=browser_group,
            major=int_or_none(major),
            minor=int_or_none(minor),
            priority=priority,
            )
Example #2
0
 def clean_bits_per_pixel(self):
     """Convert color depth to integer."""
     return int_or_none(self.cleaned_data['bits_per_pixel'])
Example #3
0
 def clean_width(self):
     """Convert screen size to integer."""
     return int_or_none(self.cleaned_data['width'])
Example #4
0
def submit(http_request, username, encrypted_password, url, browsers):
    """
    Submit a new group of screenshot requests.

    Arguments
    ~~~~~~~~~
    * username string (your user account on the server)
    * encrypted_password string (lowercase hexadecimal, length 32)
    * url string (request screenshots of this website)
    * browsers list (platform, name and version for each browser)

    Return value
    ~~~~~~~~~~~~
    * id int (request group id)

    You can use the returned request group id to check the progress of
    the screenshot requests with requests.status.
    """
    # Get user from database
    try:
        user = User.objects.get(username=username)
    except User.DoesNotExist:
        raise Fault(404, "User not found.")
    # Verify authentication
    nonces.verifyUser(http_request, user, encrypted_password)
    # Check priority
    priority = 0
    if 'shotserver04.priority' in settings.INSTALLED_APPS:
        from shotserver04.priority import user_priority
        priority = user_priority(user)
        if priority < 1:
            raise Fault(402, "Priority processing is required.")
    # Create domain and website if needed
    url = normalize_url(url)
    domain_name = extract_domain(url, remove_www=True)
    domain = Domain.objects.get_or_create(name=domain_name)[0]
    website = Website.objects.get_or_create(domain=domain, url=url)[0]
    # Create request group
    expire = datetime.now() + timedelta(minutes=30)
    ip = http_request.META['REMOTE_ADDR']
    request_group = RequestGroup.objects.create(website=website,
                                                user=user,
                                                ip=ip,
                                                expire=expire,
                                                priority=priority)
    # Create browser requests
    platforms = Platform.objects.all()
    browser_groups = BrowserGroup.objects.all()
    for name in browsers:
        parts = name.split('_')
        if len(parts) != 4:
            continue
        platform_name, browser_name, major, minor = parts
        platform_name = platform_name.replace('-', ' ')
        platform = find_by_name(platforms, platform_name)
        if platform is None:
            continue
        browser_group = find_by_name(browser_groups, browser_name)
        if browser_group is None:
            continue
        Request.objects.get_or_create(
            request_group=request_group,
            platform=platform,
            browser_group=browser_group,
            major=int_or_none(major),
            minor=int_or_none(minor),
            priority=priority,
        )
    return request_group.id
Example #5
0
def submit(http_request, username, encrypted_password, url, browsers):
    """
    Submit a new group of screenshot requests.

    Arguments
    ~~~~~~~~~
    * username string (your user account on the server)
    * encrypted_password string (lowercase hexadecimal, length 32)
    * url string (request screenshots of this website)
    * browsers list (platform, name and version for each browser)

    Return value
    ~~~~~~~~~~~~
    * id int (request group id)

    You can use the returned request group id to check the progress of
    the screenshot requests with requests.status.
    """
    # Get user from database
    try:
        user = User.objects.get(username=username)
    except User.DoesNotExist:
        raise Fault(404, "User not found.")
    # Verify authentication
    nonces.verifyUser(http_request, user, encrypted_password)
    # Check priority
    priority = 0
    if 'shotserver04.priority' in settings.INSTALLED_APPS:
        from shotserver04.priority import user_priority
        priority = user_priority(user)
        if priority < 1:
            raise Fault(402, "Priority processing is required.")
    # Create domain and website if needed
    url = normalize_url(url)
    domain_name = extract_domain(url, remove_www=True)
    domain = Domain.objects.get_or_create(name=domain_name)[0]
    website = Website.objects.get_or_create(domain=domain, url=url)[0]
    # Create request group
    expire = datetime.now() + timedelta(minutes=30)
    ip = http_request.META['REMOTE_ADDR']
    request_group = RequestGroup.objects.create(
        website=website, user=user, ip=ip,
        expire=expire, priority=priority)
    # Create browser requests
    platforms = Platform.objects.all()
    browser_groups = BrowserGroup.objects.all()
    for name in browsers:
        parts = name.split('_')
        if len(parts) != 4:
            continue
        platform_name, browser_name, major, minor = parts
        platform_name = platform_name.replace('-', ' ')
        platform = find_by_name(platforms, platform_name)
        if platform is None:
            continue
        browser_group = find_by_name(browser_groups, browser_name)
        if browser_group is None:
            continue
        Request.objects.get_or_create(
            request_group=request_group,
            platform=platform,
            browser_group=browser_group,
            major=int_or_none(major),
            minor=int_or_none(minor),
            priority=priority,
            )
    return request_group.id