-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
42 lines (35 loc) · 1.05 KB
/
utils.py
File metadata and controls
42 lines (35 loc) · 1.05 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
# this is collection of helper methods
import os
import json
def correct_name_generator(name):
# general purpose method. used for various situations
return name.replace('/', '-')
def get_svg(image_name):
name, ext = os.path.splitext(image_name)
return name +'.svg'
def get_html(image_name):
name, ext = os.path.splitext(image_name)
return name +'.html'
def create_subdir(dir1, dir2):
subdirname = os.path.join(dir1, dir2)
try:
os.mkdir(subdirname)
except FileExistsError as exc:
subdirname = generate_unique_dirname(subdirname)
os.mkdir(subdirname)
return subdirname
def set_cookie():
cookie_file = open('cookies.json', 'r')
cookie_dict = json.load(cookie_file)
cookie_file.close()
return cookie_dict
def generate_unique_dirname(dir_):
while os.path.exists(dir_):
dir_ += '-1'
return dir_
if __name__ == '__main__':
# this is for testing
#new_dir = os.path.exists('')
''' '''
dir_ = '/home/dgach/Desktop/http client/a'
generate_unique_dirname(dir_)