forked from vdt/deepdrive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
69 lines (58 loc) · 2.13 KB
/
Copy pathutils.py
File metadata and controls
69 lines (58 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/python
from __future__ import print_function
import csv
import json
import os
import subprocess
import sys
import urllib
import zipfile
import shutil
import errno
import requests
from constants import *
def download_file(url, path):
"""Good for downloading large files from dropbox as it sets gzip headers and decodes automatically on download"""
with open(path, "wb") as f:
print('Downloading', url)
response = requests.get(url, stream=True)
total_length = response.headers.get('content-length')
if total_length is None: # no content length header
f.write(response.content)
else:
dl = 0
total_length = int(total_length)
for data in response.iter_content(chunk_size=4096):
dl += len(data)
f.write(data)
done = int(50 * dl / total_length)
sys.stdout.write("\r[%s%s]" % ('=' * done, ' ' * (50 - done)))
sys.stdout.flush()
def download_folder(url, path):
"""Useful for downloading a folder / zip file from dropbox and unzipping it to path"""
print('Downloading', url)
location = urllib.urlretrieve(url)
location = location[0]
zip_ref = zipfile.ZipFile(location, 'r')
print('Unzipping', location, 'to', path)
try:
zip_ref.extractall(path)
except Exception:
print('You may want to close all programs that may have these files open or delete existing '
'folders this is trying to overwrite')
raise
finally:
zip_ref.close()
os.remove(location)
def get_config():
if os.path.isfile(os.path.join(DEEP_DRIVE_CONFIG_LOCATION)):
with open(DEEP_DRIVE_CONFIG_LOCATION, 'r') as infile:
return json.load(infile)
def processes_are_running(expected):
expected = set(expected)
actual = subprocess.Popen('tasklist.exe /fo csv', stdout=subprocess.PIPE, universal_newlines=True)
actual = list(csv.DictReader(actual.stdout))
actual = [p['Image Name'] for p in actual]
intersection = set(actual).intersection(expected)
ret = intersection == expected
return ret