-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneral.py
More file actions
72 lines (55 loc) · 1.58 KB
/
Copy pathgeneral.py
File metadata and controls
72 lines (55 loc) · 1.58 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
70
71
72
import os
def create_project_dir(directory):
if not os.path.exists(directory):
print('creating directory: ' + directory)
os.makedirs(directory)
def create_data_files(project_name, base_url, directory):
queue = directory + '/queue.txt'
crawled = directory + '/crawled.txt'
databased = directory + '/databased.txt'
domains_covered = directory + '/domains_covered.txt'
sql = directory +'/'+ project_name+'.sql'
print('creating queue file')
write_file(queue, base_url)
print('creating crawled file')
write_file(crawled, '')
print('creating sql file')
write_file(sql, '')
print('creating databased file')
write_file(databased, '')
print('creating domains file')
write_file(domains_covered, '')
def write_file(path,data):
f = open(path, 'w')
f.write(data)
f.close()
def append_to_file(path, data):
with open(path, 'a') as file :
file.write(data + '\n')
def delete_file_contents(path):
with open(path, 'w'):
pass
def file_to_set(file_name):
results = set()
with open(file_name, 'rt') as f:
for line in f:
results.add(line.replace('\n', ''))
return results
def set_to_file(links, file):
delete_file_contents(file)
for link in sorted(links):
append_to_file(file, link)
def file_to_list(file_name):
results = []
with open(file_name, 'r') as f:
for line in f:
results.append(line.replace('\n', ''))
return results
def get_path(filename):
if '/' not in filename:
return ''
splitpath = filename.split('/')
path = ''
for i in range(0, len(splitpath)-1):
path += splitpath[i]
return path