=== modified file 'plugins/vim.py' --- plugins/vim.py 2010-05-10 15:01:55 +0000 +++ plugins/vim.py 2010-05-14 20:56:53 +0000 @@ -14,6 +14,7 @@ from desktopcouch.records.server import CouchDatabase from desktopcouch.records.record import Record as CouchRecord from core.stipple import PluginBase +from couchdb.client import ResourceConflict database = CouchDatabase("packages", create=True) databaserecord = "" @@ -27,7 +28,6 @@ """ Function doc """ self.name = "Vim" self.icon = None - #self.vimDir = self.homePath + "/.vim" def sync(self): ''' get simple list of installed apps to search for config files ''' @@ -36,10 +36,12 @@ ''' write the vim config to a couchdb ''' with open(VIM_CONFIG, 'r') as vim: vr = vim.read() - print vr ##debug - - - record_four = CouchRecord({ "_id" : "vim" , + vim.close() + try: + record = database.get_record("vim") + record["file"] = vr + except TypeError: + record = CouchRecord({ "_id" : "vim" , "profile" : "user001" , "type" : "dotfile" , "file" : vr , @@ -49,18 +51,24 @@ tar = tarfile.open(HOME_DIR + "/vim.tar", "w") tar.add(VIM_DIR) tar.close() - record_four.attach(open(HOME_DIR + "/vim.tar", "r"), "vim.tar", "tarfile/tar") + if len(record.list_attachments()) > 0: + record.detach(record.list_attachments()[0]) + record.attach(open(HOME_DIR + "/vim.tar", "r"), "vim.tar", "tarfile/tar") os.remove(HOME_DIR + "/vim.tar") - databaserecord = database.put_record(record_four) - vim.close() + try: + databaserecord = database.put_record(record) + except ResourceConflict: + print "hay un error" else: - print "Bash it's not even installed SUCKER!" return def restore(self): - map_js2 = 'function(doc){if (doc._id == "vim"){emit(null,doc.file);}}' - database.add_view("vimconfig", map_js2, None, "getfile") - result = database.execute_view("vimconfig", "getfile") + try: + record = database.get_record["vim"] + result = record["file"] + except TypeError, KeyError: + print "some error message" + return for row in result: config_iter = row.value @@ -68,8 +76,7 @@ vim_file = open(os.path.expanduser("~") + "/.vimrc", 'w') vim_file.write(config_iter) vim_file.close() - rec = database.get_record("vim") - if len(rec.list_attachments()) > 0: + if len(record.list_attachments()) > 0: tar = open(os.path.expanduser("~") + "/vim.tar", 'w') tar.write(rec.attachment_data(rec.list_attachments()[0])[0]) tar.close()