-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploadsoftware.py
More file actions
executable file
·97 lines (84 loc) · 2.95 KB
/
uploadsoftware.py
File metadata and controls
executable file
·97 lines (84 loc) · 2.95 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Create custom software by specifying a directory containing core files.
"""
import sys
import json
import os
import tarfile
import addytool
cs_root = os.path.abspath(sys.argv[1])
def create_downloads():
"""Uploads files and returns IDs
Files are uploaded directly, whereas non-files are uploaded as .tar.gz files
"""
file_upload = addytool.endpoint.FileUpload()
ignored_files = [
".DS_Store",
".git",
".gitignore",
"installation_script.sh",
"removal_script.sh",
"condition_script.sh",
"base_identifier.txt",
"identifier.txt",
"version.txt"
]
file_ids = []
for file_ in os.listdir(cs_root):
if file_ not in ignored_files:
target_file = cs_root + "/" + file_
if os.path.isfile(target_file):
uploaded_file = json.loads(file_upload.post(target_file))
file_ids.append(uploaded_file)
else:
o_cwd = os.getcwd()
os.chdir(cs_root)
output_filename = target_file + ".tar.gz"
with tarfile.open(output_filename, "w:gz") as tar:
tar.add(target_file, arcname=os.path.basename(target_file))
uploaded_file = json.loads(file_upload.post(output_filename))
os.remove(output_filename)
os.chdir(o_cwd)
file_ids.append(uploaded_file)
return file_ids
def read_file(target_file):
file_to_read = cs_root + "/" + target_file
if os.path.isfile(file_to_read):
with open(file_to_read) as file_:
f_ = file_.read()
return f_
return ""
def determine_identifier():
__identifier = "identifier.txt"
abspath_identifier = cs_root + "/" + "identifier.txt"
if os.path.isfile(abspath_identifier):
pass
else:
__identifier = "base_identifier.txt"
return __identifier
def determine_if_update(identifier):
if identifier == "base_identifier.txt":
return False
return True
def create_identifier(new_identifier):
file_to_write = cs_root + "/" + "identifier.txt"
with open(file_to_write, 'w') as file_:
file_.write(new_identifier)
def create_installation_script():
pass
def create_custom_software():
custom_software = addytool.endpoint.CustomSoftware()
identifier = determine_identifier()
new_software = custom_software.post(\
identifier=read_file(identifier).rstrip('\n'), \
version=read_file("version.txt").rstrip('\n'), \
update=determine_if_update(identifier),\
downloads=create_downloads(), \
installation_script=read_file("installation_script.sh"), \
conditional_script=read_file("condition_script.sh"), \
removal_script=read_file("removal_script.sh") \
)
if identifier == "base_identifier.txt":
create_identifier(new_software['identifier'])
create_custom_software()