Commits

Guillermo Szeliga committed 313e7f5 Draft

- Account configuration is now saved at home directory

Comments (0)

Files changed (5)

api/shelf/configuration/accounts.py

+import os
 from api.shelf.registry.clients import StorageClientsRegistry
 
+import simplejson as json
+from api.shelf.configuration import config
+
 __author__ = 'guillermo'
 
 
+
 class AccountsManager():
 
     def __init__(self, client_class):
         return self.__account_type_class.get_configuration_fields()
 
     def create(self, account_config_values):
-        print 'Instantiates a new account data object'
+        return self.__account_type_class(json.dumps(account_config_values))
 
     def authorize(self, account_data):
         print 'Connects using account info and expected adapter in order to authorize our application and return new account data'
     def load(self, id=None):
         pass
 
-    def save(self, account_data, unique_account_name):
-        print 'Save file into home'
+    def save(self, account_data):
+
+        filename= self.__client_class.registry_metadata().unique_id() + "_" + account_data.unique_id() + ".json"
+        account_data.save(os.path.join(config.ConfigurationManager.APP_INSTANCES_PATH, filename))
 
     def delete(self, id=None):
         pass

api/shelf/console/shell.py

 			field_values = {}
 
 			for field in account_fields_descriptor:
-				value=raw_input(field.label() + ": ")
+				value=raw_input(">> " + field.label() + ": ")
 
 				field_values[field.name()]=value
 
-
-			print field_values
-
 			#2- Creates new account data
 			account_data = account_manager.create(field_values)
 
 			#3- If account needs authorization
-			account_data = account_manager.authorize(account_data)
+			#account_data = account_manager.authorize(account_data)
 
 			#4- Save data into a file
-			account_manager.save(account_data, 'UNIQUE_ACCOUNT_NAME')
+			account_manager.save(account_data)
+
+			print 'Account created successfully'
 
 
 	@single_client_command

api/storages/adapters/box/adapter.py

 
 	def __init__(self, account_data):
 
-		skeleton.StorageAccountData.__init__(self)
+		parsed_data = skeleton.StorageAccountData.parse(self, account_data)
 
-		parsed_data = skeleton.StorageAccountData.parse(self, account_data)
+		skeleton.StorageAccountData.__init__(self,parsed_data)
 
 		self._appKey = parsed_data["appKey"]
 		self._oauth_token = None
 	def get_configuration_fields():
 		return skeleton.StorageAccountData._list_account_field('box')
 
-	@staticmethod
-	def create_descriptor(properties=None,interactiveMode=False):
-		print 'Interactive creation ....'
-
 	def jsonize(self):
-		return dict({'appKey': self._appKey, 'OAuthToken' : self._oauth_token, 'OAuthTokenSecret': self._oauth_token_secret})
+		return dict({'appKey': self._appKey, 'OAuthToken' : self._oauth_token, 'OAuthTokenSecret': self._oauth_token_secret, 'unique_id': self.unique_id()})

api/storages/adapters/dropbox/adapter.py

 
 	def __init__(self, account_data):
 
-		skeleton.StorageAccountData.__init__(self)
+		parsed_data = skeleton.StorageAccountData.parse(self, account_data)
 
-		parsed_data = skeleton.StorageAccountData.parse(self, account_data)
+		skeleton.StorageAccountData.__init__(self, parsed_data)
 
 		self._appKey = parsed_data["appKey"]
 		self._appSecret = parsed_data["appSecret"]
 		return self._oauth_token_secret is not None and self._oauth_token is not None
 
 	def jsonize(self):
-		return dict({'appKey': self._appKey, 'appSecret': self._appSecret, 'accessType': self._accessType, 'OAuthToken' : self._oauth_token, 'OAuthTokenSecret': self._oauth_token_secret})
+		return dict({'appKey': self._appKey, 'appSecret': self._appSecret, 'accessType': self._accessType, 'OAuthToken' : self._oauth_token, 'OAuthTokenSecret': self._oauth_token_secret, 'unique_id': self.unique_id()})
 

api/storages/adapters/skeleton.py

 
 class StorageAccountData(json_types.JSonizable):
 
-	def __init__(self):
-		pass
+	UNIQUE_ID_FIELD = 'unique_id'
+
+	def __init__(self, account_data):
+		self.__unique_id = account_data[self.UNIQUE_ID_FIELD]
 
 	def parse(self,account_data):
 		return json_types.JSonizable.fromJSON(self,account_data)
 
-	def save(self,target):
-		pass
+	def save(self,target_path):
+
+		file = open(target_path,'w')
+		file.write(self.toJSON())
+
+
+	def unique_id(self):
+		return self.__unique_id
 
 	@staticmethod
 	@abc.abstractmethod
 
 	@staticmethod
 	def _list_account_field(account_id):
-		return __accounts_field_registry__[account_id]
+		fields_registry =  __accounts_field_registry__[account_id]
+		fields_registry.append(AccountFieldDescriptor(StorageAccountData.UNIQUE_ID_FIELD,'Account Name'))
 
-	@staticmethod
-	@abc.abstractmethod
-	def create_descriptor(properties=None,interactive=False):
-		pass
+		return fields_registry
+
 
 class AccountFieldDescriptor():