-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsplit.py
24 lines (18 loc) · 803 Bytes
/
split.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
import subprocess
PART_SIZE = int(1.4 * 1024 * 1024 * 1024)
def compress(path, filename):
if not os.path.isdir('{}/_rar'.format(path)):
os.mkdir('{}/_rar'.format(path))
command = 'rar a -y -v{}b "{}/_rar/{}.rar" "{}/{}"'.format(
str(PART_SIZE), path, filename, path, filename
)
subprocess.check_output(command, shell=True)
return 1+int(os.path.getsize('{}/{}'.format(path, filename)) / PART_SIZE)
def must_split(path, filename):
return os.path.getsize(path + '/' + filename) > PART_SIZE
def get_compressed_filenames(filename, nof_parts):
return ['{}.part{}.rar'.format(filename, n) for n in range(1, nof_parts+1)]
def clean_compressed_files(path, parts_filenames):
for f in parts_filenames:
os.remove('{}/_rar/{}'.format(path, f))