Commits

Guillermo Szeliga committed 0e5abe4 Draft

- Working on joining up remote paths to local ones.

  • Participants
  • Parent commits e2e590e

Comments (0)

Files changed (11)

api/shelf/console/shell.py

   __prompt_delimiter = '>'
   __registry = StorageClientsRegistry()
   __client_class = None
+  __client_instance = None
 
 
   prompt = __default_prompt + __prompt_delimiter
 
   CMD_REGISTRY_OPTIONS = ['list', 'use', 'dismiss']
   CMD_ACCOUNT_OPTIONS = ['connect', 'create', 'list', 'delete']
+  CMD_STORAGE_OPTIONS = ['join-up']
 
   def __init__(self):
     cmd.Cmd.__init__(self)
     return True
 
   @single_client_command
+  def do_storage(self, operation):
+
+    operation_parts = operation.rsplit(" ")
+
+    if operation_parts[0] == 'join-up':
+
+      #account tangle /LinuxJournal/201101.pdf /home/guillermo/cloudster/201101.pdf
+
+      #1- We should be able to tangle a source dir to a target dir
+      #2- We should be able to tangle a file to a target folder (and build the remaining path)
+
+      remote_path = operation_parts[1]
+      local_path = operation_parts[2] 
+
+      if self.__client_instance is not None:
+        self.__client_instance.read(remote_path,local_path)
+      else:
+        print 'Not session found'
+
+
+  @single_client_command
   def do_account(self, operation):
 
     account_manager = AccountsManager(self.__client_class)
       account_data = account_manager.create(field_values)
 
       #3- If account needs authorization
-      client,account_data = account_manager.authorize(account_data)
+      self.__client_instance,account_data = account_manager.authorize(account_data)
 
       #4- Save data into a file
       account_manager.save(account_data)
 
         try:
           account_data = account_manager.load(account_unique_id)
-          client = account_manager.connect(account_data)
+          self.__client_instance = account_manager.connect(account_data)
 
           print 'Account \'%s\' successfully connected' % account_unique_id
 
       else:
         print 'The account unique id was not specified'
 
-
       
   @single_client_command
   def do_disconnect(self, operation):
       ]
     return completions
 
+  def complete_storage(self, text, line, begidx, endidx):
+    if not text:
+      completions = self.CMD_STORAGE_OPTIONS[:]
+    else:
+      completions = [ f
+              for f in self.CMD_STORAGE_OPTIONS
+              if f.startswith(text)
+      ]
+    return completions
+
   def __update_prompt(self):
 
     prompt_string = None

api/storages/adapters/box/adapter.py

 	def write(self, target_full_path, source_file, overwrite=True):
 		self._client.upload(target_full_path, source_file)
 
-	def read(self, full_remote_path, target_file_path=None):
+	def read(self, full_remote_resource_path, full_local_resource_path=None):
 
-		remote_file = self._client.download(full_remote_path)
+		remote_file = self._client.download(full_remote_resource_path)
 
-		if target_file_path is not None:
+		if full_local_resource_path is not None:
 
-			f = open(target_file_path,'wb')
+			f = open(full_local_resource_path,'wb')
 
 			meta = remote_file.info()
 			file_size = int(meta.getheaders("Content-Length")[0])
 
-			print "Downloading: %s Bytes: %s" % (target_file_path, file_size)
+			print "Downloading: %s Bytes: %s" % (full_local_resource_path, file_size)
 
 			file_size_dl = 0
 			block_sz = 1024*1024

api/storages/adapters/box/test.py

         self._client.list('/Cryptography/Week1')
         self._client.list('/LinuxJournal/201101.pdf')
 
-    @unittest.skip("test_003_read: Skipped until upload service is up again")
+    #@unittest.skip("test_003_read: Skipped until upload service is up again")
     def test_003_read(self):
         self._client.read('/LinuxJournal/201101.pdf','/home/guillermo/test.pdf')
 
     def test_004_remove(self):
         self._client.remove('/Cryptography/Week1/cloudster/README')
 
+    @unittest.skip("Not fully implemented yet")
     def test_005_translateEvents(self):
 
         print 'Testing events translations....'

api/storages/adapters/box/test_data/box_account.json

 {
  "appKey":"xfbtm1x8mu7gg7v3arbqas11ly9zrsm2",
  "OAuthToken":"xfbtm1x8mu7gg7v3arbqas11ly9zrsm2",
- "OAuthTokenSecret":"x4yp0osc7ll3ss9eafr74rbo8fpov6nk"
+ "OAuthTokenSecret":"x4yp0osc7ll3ss9eafr74rbo8fpov6nk",
+ "unique_id": "my-test-box"
 }

api/storages/clients/box/client.py

 		for level in path_levels:
 			id,type = self._find_leaf_id(level, current_level_id)
 
+			print 'Found (%s): %s_%s' %  (level,id,type)
+
 			if id is not None:
 
 				covered_path[level]=id
 
 	def _get_folder_items(self, folder_id):
 
+		print 'Folder: %s' % folder_id
+
 		headers = {'Authorization' : self._session.build_auth_header()}
 
 		return json.loads(self._do_https_request('GET','api.box.com','/2.0/folders/%(folder_id)s/items' % {'folder_id' : folder_id}, headers).read())

api/storages/utils/__init__.py

+#init

api/storages/utils/facades.py

+class StorageButler(object):
+
+  def  __init__(self, storage_client):
+    pass
+
+  def joinUp(self, remote_path, local_path):
+    #1 - Consider copy of files or folders
+
+   pass 
+

docs/cloudster_brain_brain/brain_cdbb/ENTRIES-BODY-10.clb

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta name="generator" content="EditLive! 7.6.2.10" />
+<meta name="generator" content="TheBrain 7.0.4.5" />
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<style type="text/css">
+<!--
+body {
+font-family: Arial;  font-size: small;  background: #ffffff;  color: #000000;
+}
+p {
+margin-top: 0pt;  margin-bottom: 0pt;
+}
+-->
+</style>
+</head>
+<body>
+<p>Cuando nos soliciten borrar una cuenta, no solamente deberíamos borrar la metadata asociado, sino que también tenemos que definir que vamos a hacer exáctamente con los ficheros asociados. De momento, yo voto por desconectarlos y dejarlos tal cual estan en el sistema y permitir luego asociarlos a alguna otra cuenta o semejante</p>
+</body>
+</html>

docs/cloudster_brain_brain/brain_cdbb/ENTRIES-BODY-11.clb

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta name="generator" content="EditLive! 7.6.2.10" />
+<meta name="generator" content="TheBrain 7.0.4.5" />
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<style type="text/css">
+<!--
+body {
+font-family: Arial;  font-size: small;  background: #ffffff;  color: #000000;
+}
+p {
+margin-top: 0pt;  margin-bottom: 0pt;
+}
+-->
+</style>
+</head>
+<body>
+<p>Sequimos pidiendo el AppKey, cuando esto debería formar parte de la aplicación y usado implícitamente</p>
+</body>
+</html>

docs/cloudster_brain_brain/brain_cdbb/ENTRIES-BODY-9.clb

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta name="generator" content="EditLive! 7.6.2.10" />
+<meta name="generator" content="TheBrain 7.0.4.5" />
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<style type="text/css">
+<!--
+body {
+font-family: Arial;  font-size: small;  background: #ffffff;  color: #000000;
+}
+p {
+margin-top: 0pt;  margin-bottom: 0pt;
+}
+-->
+</style>
+</head>
+<body>
+<p>Cuando nos soliciten borrar una cuenta, no solamente deberíamos borrar la metadata asociado, sino que también tenemos que definir que vamos a hacer exáctamente con los ficheros asociados. De momento, yo voto por desconectarlos y dejarlos tal cual estan en el sistema y permitir luego asociarlos a alguna otra cuenta o semejante</p>
+</body>
+</html>

usefull_commandlines.txt

+python -m unittest discover {DIR} :=> Runs all test units  within a path