Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vanvalenlab / kiosk-client / 408

7 Jun 2020 - 18:00 coverage: 96.367% (-0.8%) from 97.148%
408

Pull #50

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
Merge 1b99834ef into 30e9812e4
Pull Request #50: JobManagers download zipped image results for each job.

32 of 38 new or added lines in 2 files covered. (84.21%)

610 of 633 relevant lines covered (96.37%)

4.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.23
/kiosk_client/utils.py
1
# Copyright 2016-2020 The Van Valen Lab at the California Institute of
2
# Technology (Caltech), with support from the Paul Allen Family Foundation,
3
# Google, & National Institutes of Health (NIH) under Grant U24CA224309-01.
4
# All rights reserved.
5
#
6
# Licensed under a modified Apache License, Version 2.0 (the "License");
7
# you may not use this file except in compliance with the License.
8
# You may obtain a copy of the License at
9
#
10
#     http://www.github.com/vanvalenlab/kiosk-client/LICENSE
11
#
12
# The Work provided may be used for non-commercial academic purposes only.
13
# For any other use of the Work, including commercial use, please contact:
14
# vanvalenlab@gmail.com
15
#
16
# Neither the name of Caltech nor the names of its contributors may be used
17
# to endorse or promote products derived from this software without specific
18
# prior written permission.
19
#
20
# Unless required by applicable law or agreed to in writing, software
21
# distributed under the License is distributed on an "AS IS" BASIS,
22
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
# See the License for the specific language governing permissions and
24
# limitations under the License.
25
# ============================================================================
26
"""Utility files for batch file processing"""
5×
27
from __future__ import absolute_import
5×
28
from __future__ import division
5×
29
from __future__ import print_function
5×
30

31
import os
5×
32

33
from PIL import Image
5×
34

35
from twisted.internet import reactor
5×
36
from twisted.internet.task import deferLater
5×
37

38

39
def get_download_path():
5×
40
    """Returns the default downloads path for linux or windows.
41
    https://stackoverflow.com/a/48706260
42
    """
43
    if os.name == 'nt':
5×
44
        # pylint: disable=E0401,C0415
NEW
45
        import winreg
!
NEW
46
        k = r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'
!
NEW
47
        downloads_guid = '{374DE290-123F-4565-9164-39C4925E467B}'
!
NEW
48
        with winreg.OpenKey(winreg.HKEY_CURRENT_USER, k) as key:
!
NEW
49
            location = winreg.QueryValueEx(key, downloads_guid)[0]
!
NEW
50
        return location
!
51
    location = os.path.join(os.path.expanduser('~'), 'Downloads')
5×
52
    while not os.path.exists(location):
5×
53
        location = os.path.abspath(os.path.join(location, '..'))
5×
54
    return location
5×
55

56

57
def strip_bucket_prefix(prefix):
5×
58
    """Remove any leading or trailing "/" characters."""
59
    return '/'.join(x for x in prefix.split('/') if x)
5×
60

61

62
def sleep(seconds):
5×
63
    """Simple helper to delay asynchronously for some number of seconds."""
64
    return deferLater(reactor, seconds, lambda: None)
5×
65

66

67
def is_image_file(filepath):
5×
68
    """Returns True if the file is an image file, otherwise False"""
69
    try:
5×
70
        with Image.open(filepath) as im:
5×
71
            im.verify()
5×
72
        return True
5×
73
    except:  # pylint: disable=bare-except
5×
74
        return False
5×
75

76

77
def iter_image_files(path, include_archives=True):
5×
78
    archive_extensions = {'.zip'}
5×
79
    if os.path.isfile(path):
5×
80
        _, ext = os.path.splitext(path.lower())
5×
81
        if ext in archive_extensions and include_archives:
5×
82
            yield path
5×
83
        elif is_image_file(path):
5×
84
            yield path
5×
85

86
    for (dirpath, _, filenames) in os.walk(path):
5×
87
        for filename in filenames:
5×
88
            filepath = os.path.join(dirpath, filename)
5×
89
            # process all zip images
90
            _, ext = os.path.splitext(filepath.lower())
5×
91
            if ext in archive_extensions and include_archives:
5×
92
                yield filepath
5×
93

94
            # process all images
95
            elif is_image_file(filepath):
5×
96
                yield filepath
5×
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc