Commits

Guillermo Szeliga committed e2e590e Draft

- Account delete operation added
- The Brain project updated with new ideas

Comments (0)

Files changed (13)

api/shelf/configuration/accounts.py

     def __build_account_filename(self, unique_account_id):
         return self.__client_class.registry_metadata().unique_id() + "_" + unique_account_id + ".json"
 
+    def __build_account_filepath(self, unique_account_id):
+        filename= self.__build_account_filename(unique_account_id)
+        return os.path.join(config.ConfigurationManager.APP_INSTANCES_PATH, filename)
+
     def save(self, account_data):
 
         self.__config_manager.settleIfNecessary()
+        account_data.save(self.__build_account_filepath(account_data.unique_id()))
 
-        filename= self.__build_account_filename(account_data.unique_id())
-        account_data.save(os.path.join(config.ConfigurationManager.APP_INSTANCES_PATH, filename))
+    def delete(self, unique_account_id):
 
-    def delete(self, id=None):
-        pass
+        os.remove(self.__build_account_filepath(unique_account_id))
 
     def list(self):
 
             result = re.match(name_expression_compiled,account_name)
             account_ids.append(result.group(1))
 
-        return account_ids
+        return account_ids
+
+    def exists(self,unique_account_id):
+
+        try:
+            self.list().index(unique_account_id)
+            return True
+        except ValueError:
+            return False

api/shelf/console/shell.py

 #http://alex.kavanagh.name/2011/05/exploring-python-decorators/
 #http://www.saltycrane.com/blog/2008/01/how-to-use-args-and-kwargs-in-python/
 def single_client_command(f):
-	@wraps(f)
-	def wrapped(*args,**kwds):
+  @wraps(f)
+  def wrapped(*args,**kwds):
 #
-#			for arg in args:
-#				print "another arg:", dir(arg)
+#     for arg in args:
+#       print "another arg:", dir(arg)
 
-		if args[0]._CloudsterShell__client_class is None:
-			print 'Non client has been selected'
-			return
+    if args[0]._CloudsterShell__client_class is None:
+      print 'Non client has been selected'
+      return
 
-		return f(*args,**kwds)
+    return f(*args,**kwds)
 
-	return wrapped
+  return wrapped
 
 def global_command(requires_session=False):
-	pass
+  pass
 
 
 class CloudsterShell(cmd.Cmd):
 
-	#doc_header = 'doc_header'
-	#misc_header = 'misc_header'
-	#undoc_header = 'undoc_header'
+  #doc_header = 'doc_header'
+  #misc_header = 'misc_header'
+  #undoc_header = 'undoc_header'
 
-	__default_prompt = 'cloudster'
-	__prompt_delimiter = '>'
-	__registry = StorageClientsRegistry()
-	__client_class = None
+  __default_prompt = 'cloudster'
+  __prompt_delimiter = '>'
+  __registry = StorageClientsRegistry()
+  __client_class = None
 
 
-	prompt = __default_prompt + __prompt_delimiter
-	intro = "\nCloudster administration console\n"
+  prompt = __default_prompt + __prompt_delimiter
+  intro = "\nCloudster administration console\n"
 
-	CMD_REGISTRY_OPTIONS = ['list', 'use', 'dismiss']
-	CMD_ACCOUNT_OPTIONS = ['connect', 'create', 'list', 'delete']
+  CMD_REGISTRY_OPTIONS = ['list', 'use', 'dismiss']
+  CMD_ACCOUNT_OPTIONS = ['connect', 'create', 'list', 'delete']
 
-	def __init__(self):
-		cmd.Cmd.__init__(self)
+  def __init__(self):
+    cmd.Cmd.__init__(self)
 
 
-	def do_EOF(self, line):
+  def do_EOF(self, line):
 
-		print '\nBye!'
-		return True
+    print '\nBye!'
+    return True
 
-	@single_client_command
-	def do_account(self, operation):
+  @single_client_command
+  def do_account(self, operation):
 
-		account_manager = AccountsManager(self.__client_class)
+    account_manager = AccountsManager(self.__client_class)
 
-		operation_parts = operation.rsplit(" ")
+    operation_parts = operation.rsplit(" ")
 
-		if operation_parts[0] == 'create':
-			account_fields_descriptor = account_manager.get_configuration_descriptor()
+    if operation_parts[0] == 'create':
+      account_fields_descriptor = account_manager.get_configuration_descriptor()
 
-			#1- Asks for all values
-			field_values = {}
+      #1- Asks for all values
+      field_values = {}
 
-			for field in account_fields_descriptor:
-				value=raw_input(">> " + field.label() + ": ")
+      for field in account_fields_descriptor:
+        value=raw_input(">> " + field.label() + ": ")
 
-				field_values[field.name()]=value
+        field_values[field.name()]=value
 
-			#2- Creates new account data
-			account_data = account_manager.create(field_values)
+      #2- Creates new account data
+      account_data = account_manager.create(field_values)
 
-			#3- If account needs authorization
-			client,account_data = account_manager.authorize(account_data)
+      #3- If account needs authorization
+      client,account_data = account_manager.authorize(account_data)
 
-			#4- Save data into a file
-			account_manager.save(account_data)
+      #4- Save data into a file
+      account_manager.save(account_data)
 
-			print 'Account created successfully'
+      print 'Account created successfully'
 
-		elif operation_parts[0] == 'connect':
+    elif operation_parts[0] == 'connect':
 
-			#TODO We need to check whether the account is already connected 
+      #TODO We need to check whether the account is already connected 
 
-			account_unique_id = None
+      account_unique_id = None
 
-			if len(operation_parts) > 1:
-				account_unique_id = operation_parts[1]
+      if len(operation_parts) > 1:
+        account_unique_id = operation_parts[1]
 
-			if account_unique_id is None:
-				account_unique_id=raw_input(">> Account name: ")
+      if account_unique_id is None:
+        account_unique_id=raw_input(">> Account name: ")
 
-			if account_unique_id is not None and len(account_unique_id) > 0:
+      if account_unique_id is not None and len(account_unique_id) > 0:
 
-				try:
-					account_data = account_manager.load(account_unique_id)
-					client = account_manager.connect(account_data)
+        try:
+          account_data = account_manager.load(account_unique_id)
+          client = account_manager.connect(account_data)
 
-					print 'Account \'%s\' successfully connected' % account_unique_id
+          print 'Account \'%s\' successfully connected' % account_unique_id
 
-				except RuntimeError, e:
-					print 'Account information could not be loaded. Reason: %s' % e
+        except RuntimeError, e:
+          print 'Account information could not be loaded. Reason: %s' % e
 
-			else:
-				print 'Account id cannot be empty'
+      else:
+        print 'Account id cannot be empty'
 
-		elif operation_parts[0] == 'list':
-			
-			for defined_account in account_manager.list():
-				print defined_account
+    elif operation_parts[0] == 'list':
+      
+      for defined_account in account_manager.list():
+        print defined_account
 
-		elif operation_parts[0] == 'delete':
-			pass
+    elif operation_parts[0] == 'delete':
 
-	@single_client_command
-	def do_disconnect(self, operation):
-		print 'Connecting....'
+      # 1- Confirm whether we have to delete or not the account
+      # 2- Disconnect all related files to the account
+      # 3- Remove the account file
 
-	@global_command
-	def do_start(self, operation):
-		print 'Starting cloudster.....'
+      account_unique_id = None
 
-	@global_command
-	def do_shutdown(self, operation):
-		print 'Shuting down cloudster.....'
+      if len(operation_parts) == 2:
 
-	def do_client(self, operation):
+        account_unique_id = operation_parts[1]
 
-		operation_parts = operation.rsplit(" ")
+        if account_unique_id is not None and account_manager.exists(account_unique_id):
 
-		if operation_parts[0] == 'list':
+          confirmed = ""
 
-			for storage_client in self.__registry.get_available():
-				print storage_client.registry_metadata()
+          while confirmed is "":
 
-		elif operation_parts[0] == 'use':
+            confirmed = raw_input("Are you sure you want to remove account '%s'? (y/n)" % account_unique_id);
 
-			if len(operation_parts) > 1:
+          if confirmed.lower() == 'y':
+            account_manager.delete(account_unique_id)
 
-				client_id = operation_parts[1]
+        else:
 
-				try:
-					self.__client_class = self.__registry.get_by_id(client_id)
-					self.__update_prompt()
-				except KeyError:
-					print "Client id '%s' couldn't be found" % client_id
-			else:
-				print 'Client id is missing'
+          print "Account with id '%s' does not exist" % account_unique_id
 
-		elif operation_parts[0] == 'dismiss':
+      else:
+        print 'The account unique id was not specified'
 
-			#TODO Close session
-			self.__client_class = None
-			self.__update_prompt()
 
-	def complete_client(self, text, line, begidx, endidx):
-		if not text:
-			completions = self.CMD_REGISTRY_OPTIONS[:]
-		else:
-			completions = [ f
-							for f in self.CMD_REGISTRY_OPTIONS
-							if f.startswith(text)
-			]
-		return completions
+      
+  @single_client_command
+  def do_disconnect(self, operation):
+    print 'Connecting....'
 
-	def complete_account(self, text, line, begidx, endidx):
-		if not text:
-			completions = self.CMD_ACCOUNT_OPTIONS[:]
-		else:
-			completions = [ f
-							for f in self.CMD_ACCOUNT_OPTIONS
-							if f.startswith(text)
-			]
-		return completions
+  @global_command
+  def do_start(self, operation):
+    print 'Starting cloudster.....'
 
-	def __update_prompt(self):
+  @global_command
+  def do_shutdown(self, operation):
+    print 'Shuting down cloudster.....'
 
-		prompt_string = None
+  def do_client(self, operation):
 
-		if self.__client_class is not None:
-			prompt_string = self.__default_prompt + '@' + self.__client_class.registry_metadata().unique_id() + self.__prompt_delimiter
-		else:
-			prompt_string = self.__default_prompt + self.__prompt_delimiter
+    operation_parts = operation.rsplit(" ")
 
-		self.prompt = prompt_string
+    if operation_parts[0] == 'list':
+
+      for storage_client in self.__registry.get_available():
+        print storage_client.registry_metadata()
+
+    elif operation_parts[0] == 'use':
+
+      if len(operation_parts) > 1:
+
+        client_id = operation_parts[1]
+
+        try:
+          self.__client_class = self.__registry.get_by_id(client_id)
+          self.__update_prompt()
+        except KeyError:
+          print "Client id '%s' couldn't be found" % client_id
+      else:
+        print 'Client id is missing'
+
+    elif operation_parts[0] == 'dismiss':
+
+      #TODO Close session
+      self.__client_class = None
+      self.__update_prompt()
+
+  def complete_client(self, text, line, begidx, endidx):
+    if not text:
+      completions = self.CMD_REGISTRY_OPTIONS[:]
+    else:
+      completions = [ f
+              for f in self.CMD_REGISTRY_OPTIONS
+              if f.startswith(text)
+      ]
+    return completions
+
+  def complete_account(self, text, line, begidx, endidx):
+    if not text:
+      completions = self.CMD_ACCOUNT_OPTIONS[:]
+    else:
+      completions = [ f
+              for f in self.CMD_ACCOUNT_OPTIONS
+              if f.startswith(text)
+      ]
+    return completions
+
+  def __update_prompt(self):
+
+    prompt_string = None
+
+    if self.__client_class is not None:
+      prompt_string = self.__default_prompt + '@' + self.__client_class.registry_metadata().unique_id() + self.__prompt_delimiter
+    else:
+      prompt_string = self.__default_prompt + self.__prompt_delimiter
+
+    self.prompt = prompt_string
 
 def main():
 
-	shell = CloudsterShell()
-	shell.cmdloop()
+  shell = CloudsterShell()
+  shell.cmdloop()
 
 
 if __name__ == "__main__":
-	main()
+  main()

api/storages/adapters/skeleton.py

 
 		file = open(target_path,'w')
 		file.write(self.toJSON())
+		file.flush()
+		file.close()
 
 
 	def unique_id(self):

docs/cloudster_brain_brain/Indexing.log

-IndexBuilder started [Tue Aug 21 12:01:10 CEST 2012]
-Reading index registry [Safe point: undefined]
-Index status: missing
-Indexing process started [Tue Aug 21 12:01:10 CEST 2012]
-Processing 2,1 [count: 1; total: 1]
-Reading index registry [Safe point: undefined]
-Writing thought 2,1
-Writing thought label 2,1
-Writing thought tags 2,1
-Updating index registry [Safe point: restarted]
-Elapsed time: 50 + 50 = 100
-Indexing process completed [Tue Aug 21 12:01:10 CEST 2012]
-Updating index registry [Safe point: restarted]
-Index status: initialized
-IndexBuilder stopped [Tue Aug 21 12:01:13 CEST 2012]
-Start indexing [Tue Aug 21 12:01:13 CEST 2012]
-Loading UrlIndexBuilder
-Loading index registry [/home/guillermo/development/workspace/cloudster/docs/cloudster_brain_brain/UrlIndexBuilder.dat]
-Loading index log [/home/guillermo/development/workspace/cloudster/docs/cloudster_brain_brain/UrlIndexBuilder.log]
-Updating index registry [Safe point: restarted]
-Index status: initialized
-Reading index registry [Safe point: undefined]
-UrlIndexBuilder created [BrainAPI = connected; backgroundRunning = true; synchronizedThread = 4; maxCPU = 0.5; showStatus = false; logFile = /home/guillermo/development/workspace/cloudster/docs/cloudster_brain_brain/UrlIndexBuilder.log; startTime = null; stopTime = null; total = 0; processed = 0; indexed = 0; indexBuilderDat = /home/guillermo/development/workspace/cloudster/docs/cloudster_brain_brain/UrlIndexBuilder.dat (empty); indexing = false]
-UrlIndexBuilder scheduled [Tue Aug 21 12:01:13 CEST 2012]
-UrlIndexBuilder started [Tue Aug 21 12:01:13 CEST 2012]
-Reading index registry [Safe point: undefined]
-Index status: safe
-Deleting index log [/home/guillermo/development/workspace/cloudster/docs/cloudster_brain_brain/UrlIndexBuilder.log]
-Indexing process started [Tue Aug 21 12:01:13 CEST 2012]
-Processing 2,1 [count: 1; total: 1]
-Indexing process completed [Tue Aug 21 12:01:13 CEST 2012]
-Indexing time: 00:00:00
Add a comment to this file

docs/cloudster_brain_brain/brain_cdbb/ACTIVITYLOG.tbl

Binary file modified.

Add a comment to this file

docs/cloudster_brain_brain/brain_cdbb/ENTRIES.tbl

Binary file modified.

Add a comment to this file

docs/cloudster_brain_brain/brain_cdbb/ENTRYTOOBJECT.tbl

Binary file modified.

Add a comment to this file

docs/cloudster_brain_brain/brain_cdbb/LINKS.tbl

Binary file modified.

Add a comment to this file

docs/cloudster_brain_brain/brain_cdbb/MODSLOG.tbl

Binary file modified.

Add a comment to this file

docs/cloudster_brain_brain/brain_cdbb/SYNCPOINTS.tbl

Binary file modified.

Add a comment to this file

docs/cloudster_brain_brain/brain_cdbb/THOUGHTS.tbl

Binary file modified.

Add a comment to this file

docs/cloudster_brain_brain/brain_db/brain.h2.db

Binary file modified.

docs/cloudster_brain_brain/brain_db/brain.trace.db

 	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 	at java.awt.EventDispatchThread.run(Unknown Source)
+10-13 02:07:31 jdbc[2]: exception
+org.h2.jdbc.JdbcSQLException: The object is already closed [90007-164]
+	at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
+	at org.h2.message.DbException.get(DbException.java:169)
+	at org.h2.message.DbException.get(DbException.java:146)
+	at org.h2.message.DbException.get(DbException.java:135)
+	at org.h2.jdbc.JdbcConnection.checkClosed(JdbcConnection.java:1393)
+	at org.h2.jdbc.JdbcConnection.checkClosed(JdbcConnection.java:1371)
+	at org.h2.jdbc.JdbcConnection.createStatement(JdbcConnection.java:191)
+	at com.thebrain.common.b.e.M(mef:39)
+	at com.thebrain.common.b.e.M(mef:231)
+	at com.thebrain.common.b.e.M(mef:128)
+	at com.thebrain.personal.a.a.l.i(zhd:729)
+	at com.thebrain.c.e.v.L(cdg:406)
+	at com.thebrain.personal.a.a.t.f(kid:307)
+	at com.thebrain.personal.view.bi.M(bcd:4043)
+	at com.thebrain.personal.controller.App.f(oqd:1143)
+	at com.thebrain.personal.view.rd.run(bcd:1938)
+	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
+	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
+	at java.awt.EventQueue.access$000(Unknown Source)
+	at java.awt.EventQueue$1.run(Unknown Source)
+	at java.awt.EventQueue$1.run(Unknown Source)
+	at java.security.AccessController.doPrivileged(Native Method)
+	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
+	at java.awt.EventQueue.dispatchEvent(Unknown Source)
+	at com.thebrain.personal.c.d.x.dispatchEvent(xyc:120)
+	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
+	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
+	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
+	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
+	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
+	at java.awt.EventDispatchThread.run(Unknown Source)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.