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

vanvalenlab / kiosk-client / 406

7 Jun 2020 - 3:09 coverage: 96.349% (-0.8%) from 97.148%
406

Pull #50

travis-ci-com

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

29 of 35 new or added lines in 2 files covered. (82.86%)

607 of 630 relevant lines covered (96.35%)

4.81 hits per line

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

86.36
/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
    return os.path.join(os.path.expanduser('~'), 'Downloads')
5×
52

53

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

58

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

63

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

73

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

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

91
            # process all images
92
            elif is_image_file(filepath):
5×
93
                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