-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject_code.py
More file actions
122 lines (120 loc) · 4.75 KB
/
project_code.py
File metadata and controls
122 lines (120 loc) · 4.75 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import os
import subprocess
import urllib2
import requests,json
path = "/home/ubuntu"
def list_files(path):
print "********The file in the local directory are: ***********"
i = 1
for file in os.listdir(path):
if not file.startswith('.') and os.path.isfile(os.path.join(path, file)):
print i,file
i = i+1
def upload_files(path):
print "*******Enter the number besides the container for uploading the file*********"
bashcom = 'curl -s https://172.31.0.154:8080/v1/AUTH_anuj?format=json -X GET -H "X-Auth-Token: AUTH_tk381d832d92c74828af7ba220d739e7b8" --insecure'
output = subprocess.Popen(bashcom, stdout=subprocess.PIPE, shell=True)
output1 = output.communicate()[0]
j = json.loads(output1)
i=1
listcontainer = []
for row in j:
listcontainer.append(row['name'])
print i,row['name']
i = i+1
index = input()
container = listcontainer[index-1]
print "********Enter the number besides the file for uploading to the repository ***********"
i = 1
list1 = []
for file in os.listdir(path):
if not file.startswith('.') and os.path.isfile(os.path.join(path, file)):
list1.append(file)
print i,file
i = i+1
index = input()
file_to_upload = list1[index-1]
bashcom ='curl -s https://172.31.0.154:8080/v1/AUTH_anuj/'+container+'/ --upload-file '+file_to_upload+ ' -H "X-Auth-Token: AUTH_tk381d832d92c74828af7ba220d739e7b8" --insecure'
output = subprocess.Popen(bashcom, stdout=subprocess.PIPE, shell=True)
output1 = output.communicate()[0] #subprocess.check_output(['bash','-c',bashcom])
print "File uploaded successfully!!!"
def list_uploaded_files(path):
print "*******Enter the number besides the container to list the file of that container*********"
bashcom = 'curl -s https://172.31.0.154:8080/v1/AUTH_anuj?format=json -X GET -H "X-Auth-Token: AUTH_tk381d832d92c74828af7ba220d739e7b8" --insecure'
output = subprocess.Popen(bashcom, stdout=subprocess.PIPE, shell=True)
output1 = output.communicate()[0]
j = json.loads(output1)
i=1
listcontainer = []
for row in j:
listcontainer.append(row['name'])
print i,row['name']
i = i+1
index = input()
container = listcontainer[index-1]
bashcom = 'curl -s https://172.31.0.154:8080/v1/AUTH_anuj/'+container+'?format=json -X GET -H "X-Auth-Token: AUTH_tk381d832d92c74828af7ba220d739e7b8" --insecure'
output = subprocess.Popen(bashcom, stdout=subprocess.PIPE, shell=True)
output1 = output.communicate()[0]
j = json.loads(output1)
i = 1
print "Files present in "+container+" are: "
for row in j:
print i,row['name']
i = i+1
def delete_uploaded_files(path):
print "*******Enter the number besides the container in which the file is to be deleted*********"
bashcom = 'curl -s https://172.31.0.154:8080/v1/AUTH_anuj?format=json -X GET -H "X-Auth-Token: AUTH_tk381d832d92c74828af7ba220d739e7b8" --insecure'
output = subprocess.Popen(bashcom, stdout=subprocess.PIPE, shell=True)
output1 = output.communicate()[0]
j = json.loads(output1)
i=1
listcontainer = []
for row in j:
listcontainer.append(row['name'])
print i,row['name']
i = i+1
index = input()
container = listcontainer[index-1]
bashcom = 'curl -s https://172.31.0.154:8080/v1/AUTH_anuj/'+container+'?format=json -X GET -H "X-Auth-Token: AUTH_tk381d832d92c74828af7ba220d739e7b8" --insecure'
output = subprocess.Popen(bashcom, stdout=subprocess.PIPE, shell=True)
output1 = output.communicate()[0]
j = json.loads(output1)
i = 1
list1= []
for row in j:
list1.append(row['name'])
print i,row['name']
i = i+1
print "***************Enter the number besides the file to delete from the repository **************"
index = input()
file_to_delete = list1[index-1]
print file_to_delete
bashcom = 'curl -s https://172.31.0.154:8080/v1/AUTH_anuj/'+container+'/'+file_to_delete+ ' -X DELETE -H "X-Auth-Token: AUTH_tk381d832d92c74828af7ba220d739e7b8" --insecure'
output = subprocess.Popen(bashcom, stdout=subprocess.PIPE, shell=True)
output1 = output.communicate()[0]
print "File deleted!!!"
while(True):
print "****************Menu********************"
print "Enter 1 for listing all files in the local directory"
print "Enter 2 to upload a specific file to the repository"
print "Enter 3 for listing files uploaded to repository"
print "Enter 4 to delete a specific file from the repository"
number = input();
if number == 1:
list_files(path)
print
print
elif number == 2:
upload_files(path)
print
print
elif number == 3:
list_uploaded_files(path)
print
print
elif number == 4:
delete_uploaded_files(path)
print
print
else:
exit()