Advertisement
Guest User

Untitled

a guest
Jul 17th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. class BoxStorage(StorageAbstract):
  2.     def __init__(self):
  3.         """
  4.        """
  5.         self.box_username = config.get_config_value('remote-storage', 'box_username')
  6.         self.box_password = config.get_config_value('remote-storage', 'box_password')
  7.         self.target = config.get_config_value('server', 'outputpath')
  8.         self.output_url = '%s%s' % (
  9.             config.get_config_value('server', 'url'),
  10.             config.get_config_value('server', 'outputurl')
  11.         )
  12.  
  13.     def store(self, output):
  14.         import shutil, tempfile, httplib2
  15.         try:
  16.             import boxsdk
  17.         except:
  18.             raise StorageDependecyError('[400]:Dependecny for Box Storage not met')
  19.  
  20.         file_name = output.file
  21.  
  22.  
  23.         (prefix, suffix) = os.path.splitext(file_name)
  24.         if not suffix:
  25.             suffix = output.output_format.get_extension()
  26.         (file_dir, file_name) = os.path.split(prefix)
  27.         output_name = tempfile.mkstemp(suffix=suffix, prefix=file_name,
  28.                                        dir=self.target)[1]
  29.  
  30.         full_output_name  = os.path.join(self.target, output_name)
  31.         # LOGGER.info('Storing file output to %s', full_output_name)
  32.         shutil.copy2(output.file, full_output_name)
  33.         just_file_name = os.path.basename(output_name)
  34.  
  35.         local_url = urljoin(self.output_url, just_file_name)
  36.  
  37.         curl_command = "curl -u %s:%s -T %s  https://dav.box.com/dav/%s" %(self.box_username,self.box_password,local_url,just_file_name)
  38.  
  39.         subp = subprocess.Popen(curl_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  40.  
  41.         curlstdout, curlstderr = subp.communicate()
  42.         url = "https://dav.box.com/%s" %just_file_name
  43.  
  44.  
  45.         return (STORE_TYPE.BOX, output_name, url)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement