anubhav77 commited on
Commit
094ca20
·
1 Parent(s): 9e15676

db relative paths

Browse files
Files changed (2) hide show
  1. dropbox_handler.py +8 -0
  2. main.py +1 -1
dropbox_handler.py CHANGED
@@ -40,12 +40,16 @@ def normalizeFilename(filename):
40
  def getDropboxFilename(localFilename):
41
  """ localFilename is $DROP_DIR2/<subpath>/<filename>"""
42
  """ dropboxFilename is $APP_PATH/<subpath>/<filename"""
 
 
43
  localFilename=normalizeFilename(localFilename)
44
  return normalizeFilename(localFilename.replace(os.environ['DROP_DIR2'],"/",1).replace("/",os.environ['APP_PATH'],1))
45
 
46
  def getLocalFilename(dropboxFilename):
47
  """ localFilename is $DROP_DIR2/<subpath>/<filename>"""
48
  """ dropboxFilename is $APP_PATH/<subpath>/<filename"""
 
 
49
  dropboxFilename=normalizeFilename(dropboxFilename)
50
  return normalizeFilename(dropboxFilename.replace(os.environ['APP_PATH'],"/",1).replace("/",os.environ['DROP_DIR2'],1))
51
 
@@ -114,8 +118,12 @@ def backupFolder(localFolder):
114
 
115
  def restoreFolder(dropboxFolder):
116
  """ list all files in dropbox folder and subfolders and restore them"""
 
117
  try:
118
  res=dbx.files_list_folder(dropboxFolder)
 
 
 
119
  except dropbox.exceptions.ApiError as err:
120
  print('Folder listing failed for', dropboxFolder, '-- assumed empty:', err)
121
  return
 
40
  def getDropboxFilename(localFilename):
41
  """ localFilename is $DROP_DIR2/<subpath>/<filename>"""
42
  """ dropboxFilename is $APP_PATH/<subpath>/<filename"""
43
+ if not localFilename.startsWith(os.environ['DROP_DIR2']):
44
+ localFilename=os.environ['DROP_DIR2']+localFilename
45
  localFilename=normalizeFilename(localFilename)
46
  return normalizeFilename(localFilename.replace(os.environ['DROP_DIR2'],"/",1).replace("/",os.environ['APP_PATH'],1))
47
 
48
  def getLocalFilename(dropboxFilename):
49
  """ localFilename is $DROP_DIR2/<subpath>/<filename>"""
50
  """ dropboxFilename is $APP_PATH/<subpath>/<filename"""
51
+ if not localFilename.startsWith(os.environ['APP_PATH']):
52
+ localFilename=os.environ['APP_PATH']+localFilename
53
  dropboxFilename=normalizeFilename(dropboxFilename)
54
  return normalizeFilename(dropboxFilename.replace(os.environ['APP_PATH'],"/",1).replace("/",os.environ['DROP_DIR2'],1))
55
 
 
118
 
119
  def restoreFolder(dropboxFolder):
120
  """ list all files in dropbox folder and subfolders and restore them"""
121
+ global TOKEN
122
  try:
123
  res=dbx.files_list_folder(dropboxFolder)
124
+ if (TOKEN != dbx._oauth2_access_token):
125
+ fbh.fb_update("d2_accesstoken",dbx._oauth2_access_token)
126
+ TOKEN=dbx._oauth2_access_token
127
  except dropbox.exceptions.ApiError as err:
128
  print('Folder listing failed for', dropboxFolder, '-- assumed empty:', err)
129
  return
main.py CHANGED
@@ -126,7 +126,7 @@ def version():
126
  def persist():
127
  print("Received persist request")
128
  retVal=bkend.persist()
129
- dbh.backupFolder("/home/user/app/index/chroma")
130
  return retVal
131
 
132
  @app.post(api_base+"/raw_sql")
 
126
  def persist():
127
  print("Received persist request")
128
  retVal=bkend.persist()
129
+ dbh.backupFolder("/index/chroma")
130
  return retVal
131
 
132
  @app.post(api_base+"/raw_sql")