-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsep.py
76 lines (57 loc) · 1.77 KB
/
sep.py
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
70
71
72
73
74
75
76
"""File disassembling related functions.
* All functions related to breaking the file
* into chunks in order to copy them are
* defined here.
"""
import os
from rem import rem, rem_read_size
import copy
import progress
def make_chunks(is_verbose=False, show_progress=False):
"""Make chunks of the file passed."""
src, des = rem('grab')
# Open the file in binary
FILE_STREAM = open(src, 'rb')
rem_read_size('register', 104857600)
# After registering show progress
if show_progress:
progress_bar = progress.progress('chunk')
progress_bar.start()
count = 0
while True:
read_size = rem_read_size('grab')
READ_CHUNK = FILE_STREAM.read(read_size) # 52428800) # 209715200)
count += 1
if not READ_CHUNK:
return True
if is_verbose:
print("Copying chunk: {}".format(count))
copy.copy_chunks(READ_CHUNK, count)
# Wait for progress bar to end
progress_bar.join()
def check_existence(src, dest):
"""Check if the source exists and destinaton does not."""
if not os.path.isfile(src):
# Show that source doesn't exist
print("{}: No such file\a".format(src))
return False
if os.path.isdir(src):
# Show that source is a folder
print("{}: is a folder".format(src))
return False
if os.path.isfile(dest):
# Show that destinaton already exists
print("{}: already exists\a".format(dest))
return False
return True
def check_filesize():
"""Check the filesize.
If the file is 0 bytes size, then no
need to use threads and all.
If it is not then return True.
"""
src, des = rem('grab')
if os.path.getsize(src) == 0:
return False
else:
return True