-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudentcode.py
More file actions
226 lines (190 loc) · 6.09 KB
/
Copy pathstudentcode.py
File metadata and controls
226 lines (190 loc) · 6.09 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#Group-1
#Project Partners -
#Dharmik Shah - 011413103 (29)
#Gargi Saraf - 011447865 (27)
#Vaidehee Barde - 011447267 (07)
# Import modules
import time
import requests,json
import subprocess
import os
import swiftclient
path = "/home/user/Desktop"
# All accounts
users = {
"dharmik": {
"password": "dharmik",
"group": "dharmik",
"mail": []
},
"gargi": {
"password": "gargi",
"group": "gargi",
"mail": []
},
"vaidehee": {
"password": "vaidehee",
"group": "vaidehee",
"mail": []
}
}
# Form validation
def validate(form):
if len(form) > 0:
return False
return True
# Login authorization
def loginauth(username, password):
if username in users:
if password == users[username]["password"]:
print("Login successful")
return True
return False
# Login
def login():
while True:
username = input("Username: ")
if not len(username) > 0:
print("Username can't be blank")
else:
break
while True:
password = input("Password: ")
if not len(password) > 0:
print("Password can't be blank")
else:
break
if loginauth(username, password):
openstac(username, password)
else:
print("Invalid username or password")
# Register
def register():
while True:
username = input("New username: ")
if not len(username) > 0:
print("Username can't be blank")
continue
else:
break
while True:
password = input("New password: ")
if not len(password) > 0:
print("Password can't be blank")
continue
else:
break
print("Creating account...")
users[username] = {}
users[username]["password"] = password
users[username]["group"] = "user"
users[username]["mail"] = []
time.sleep(1)
print("Account has been created")
##############
def openstac(username, password):
######1########
username = username
password = password
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
#####2#########
def upload_files():
# Ask the user for input
container_name2 = raw_input("Enter container name: ")
filename_name2 = raw_input("Enter file name to upload: ")
if continaer_name2 == username:
# Set up the echo command and direct the output to a pipe
output2 = os.system("swift upload "+container_name2+ " "+filename_name2)
# Run the command
print (output2)
print ("File uploaded successfully!!!")
########3#########
def list_uploaded_files():
container_name3 = raw_input("Enter container name: ")
command = 'http://130.65.159.227:8080/v1/AUTH_c69217d717bb40988d42d4dfc4da6bdf/'+container_name3
if continaer_name2 == username:
output3 = os.system("curl "+command)
print (output3)
########4#########
def delete_uploaded_files():
# Ask the user for input
container_name4 = raw_input("Enter Student name:")
subjects_name = raw_input("Enter Subject name from which you have to delete file:")
if continaer_name2 == username:
file_name4 = raw_input("Enter file name to delete: ")
output4 = os.system("swift delete "+container_name4+' '+file_name4)
print (output4)
print ("File deleted!!!")
########5#########
def container_files():
# Ask the user for input
container_name5 = raw_input("Enter container name: ")
file_name5 = raw_input("Enter folder name: ")
if continaer_name2 == username:
output5 = os.system("swift delete "+container_name5+' '+file_name5)
print (output5)
#######6#######
def download_files():
# Ask the user for input
container_name6 = raw_input("Enter container name: ")
file_name6 = raw_input("Enter file name to download: ")
if continaer_name2 == username:
output6 = os.system("swift download "+container_name6+' '+file_name6)
print (output6)
print ("File downloaded!!!")
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 Subjects list")
print ("Enter 4 to delete a specific file from the repository")
print ("Enter 5 for files in a subject")
print ("Enter 6 to download a specific file from the repository")
number = input();
if number == 1:
list_files(path)
print
print
elif number == 2:
upload_files()
print
print
elif number == 3:
list_uploaded_files()
print
print
elif number == 4:
delete_uploaded_files()
print
print
elif number == 5:
container_files()
print
print
elif number == 6:
download_files()
print
print
else:
exit()
while True:
print ("****************Menu********************")
print ("Enter 1 to login")
print ("Enter 2 to register")
number = input();
if number == 1:
login()
print
print
elif number == 2:
register()
print
print
else:
exit()