-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_to_dropbox.py
90 lines (70 loc) · 3.03 KB
/
upload_to_dropbox.py
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
import sys
import dropbox
from dropbox.files import WriteMode
from dropbox.exceptions import ApiError, AuthError
#*******************************************************************#
##This will Provide metadata of the files on drop box
##import dropbox
##
##def print_metadata(dbfile):
## md = dbx.files_get_metadata(dbfile)
## print (md)
##
##dbx = dropbox.Dropbox('oG7g0mYYCfAAAAAAAAAAD71siPToPbfzNVclK-9lY-jDzYahVep2AGKFXymw8jC3')
##
##myfiles = ['/frozen_inference_graph.pb']
##
##for myfile in myfiles:
## print_metadata(myfile)
#*******************************************************************#
# Access token
TOKEN = 'oG7g0mYYCfAAAAAAAAAAD71siPToPbfzNVclK-9lY-jDzYahVep2AGKFXymw8jC3'
LOCALFILE = 'C:\\Users\\Admin\\Desktop\\KJSCE_Object_Detection\\models\\research\\object_detection\\inference_graph\\frozen_inference_graph.pb'
BACKUPPATH = '/frozen_inference_graph.pb' # Keep the forward slash before destination filename
# Uploads contents of LOCALFILE to Dropbox
def backup():
with open(LOCALFILE, 'rb') as f:
# We use WriteMode=overwrite to make sure that the settings in the file
# are changed on upload
print("Uploading " + LOCALFILE + " to Dropbox as " + BACKUPPATH + "...")
try:
dbx.files_upload(f.read(), BACKUPPATH, mode=WriteMode('overwrite'))
except ApiError as err:
# This checks for the specific error where a user doesn't have enough Dropbox space quota to upload this file
if (err.error.is_path() and
err.error.get_path().error.is_insufficient_space()):
sys.exit("ERROR: Cannot back up; insufficient space.")
elif err.user_message_text:
print(err.user_message_text)
sys.exit()
else:
print(err)
sys.exit()
# Adding few functions to check file details
def checkFileDetails():
print("Checking file details")
for entry in dbx.files_list_folder('').entries:
print("File list is : ")
print(entry.name)
# Run this script independently
if __name__ == '__main__':
# Check for an access token
if (len(TOKEN) == 0):
sys.exit("ERROR: Looks like you didn't add your access token. Open up backup-and-restore-example.py in a text editor and paste in your token in line 14.")
# Create an instance of a Dropbox class, which can make requests to the API.
print("Creating a Dropbox object...")
dbx = dropbox.Dropbox(TOKEN, timeout=None)
# Check that the access token is valid
try:
dbx.users_get_current_account()
except AuthError as err:
sys.exit(
"ERROR: Invalid access token; try re-generating an access token from the app console on the web.")
try:
checkFileDetails()
except Error as err:
sys.exit("Error while checking file details")
print("Creating backup...")
# Create a backup of the current settings file
backup()
print("Done!")