~kermiac/+junk/stipple_empathy-plugins

« back to all changes in this revision

Viewing changes to plugins/vim.py

  • Committer: duanedesign
  • Date: 2010-05-10 15:01:55 UTC
  • mfrom: (10.1.2 stipple_test)
  • Revision ID: duanedesign@gmail.com-20100510150155-yahw9en9rv21fq8b
implemented couch attachments in emacs plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
DocString Paragraph
7
7
 
8
8
"""
9
 
 
10
9
__version__ = "$Revision$"
11
10
 
12
 
 
13
11
import os
14
12
import commands
 
13
import tarfile
15
14
from desktopcouch.records.server import CouchDatabase
16
15
from desktopcouch.records.record import Record as CouchRecord
17
16
from core.stipple import PluginBase
20
19
databaserecord = ""
21
20
RECORD_TYPE = 'http://www.okiebuntu.homelinux.com/packagesync'
22
21
VIM_CONFIG = os.path.expanduser("~") + "/.vimrc"
 
22
HOME_DIR = os.path.expanduser("~")
 
23
VIM_DIR = HOME_DIR + "/.vim"
23
24
 
24
25
class Plugin(PluginBase):
25
 
 
26
26
    def __init__ (self):
27
27
        """ Function doc """
28
28
        self.name = "Vim"
36
36
            ''' write the vim config to a couchdb '''
37
37
            with open(VIM_CONFIG, 'r') as vim:
38
38
                vr = vim.read()
39
 
            print vr
 
39
            print vr ##debug
40
40
 
41
41
 
42
42
            record_four = CouchRecord({  "_id"       :  "vim"   ,  
45
45
                                        "file"      :  vr        ,
46
46
                                     },
47
47
                                     record_type = RECORD_TYPE)
48
 
 
 
48
            if os.path.exists(VIM_DIR):
 
49
                tar = tarfile.open(HOME_DIR + "/vim.tar", "w")
 
50
                tar.add(VIM_DIR)
 
51
                tar.close()
 
52
                record_four.attach(open(HOME_DIR + "/vim.tar", "r"), "vim.tar", "tarfile/tar")
 
53
                os.remove(HOME_DIR + "/vim.tar")
49
54
            databaserecord = database.put_record(record_four)
50
55
            vim.close()
51
56
        else:
52
57
            print "Bash it's not even installed SUCKER!"
53
58
            return
54
 
 
55
 
 
56
 
        # the part for taring the vim directory
57
 
        #if os.path.isdir(vimdir):
58
 
        #    tar = tarfile.open(self.name.lower()+".tar", "w")
59
 
        #    tar.add(vimDir)
60
 
        #    tar.close()
61
 
        #    saveDir(vimDir)
62
 
        # maybe use https://launchpad.net/ubuntuone-storage-protocol
63
59
        
64
60
    def restore(self):
65
61
        map_js2 = 'function(doc){if (doc._id == "vim"){emit(null,doc.file);}}'
66
62
        database.add_view("vimconfig", map_js2, None, "getfile")
67
63
        result = database.execute_view("vimconfig", "getfile")
68
 
 
 
64
        
69
65
        for row in result:
70
66
            config_iter = row.value
71
67
 
72
 
        vim_file = open(os.path.expanduser("~") + "/.vimrc2", 'w')
 
68
        vim_file = open(os.path.expanduser("~") + "/.vimrc", 'w')
73
69
        vim_file.write(config_iter)
74
70
        vim_file.close()
 
71
        rec = database.get_record("vim")
 
72
        if len(rec.list_attachments()) > 0:
 
73
            tar = open(os.path.expanduser("~") + "/vim.tar", 'w')
 
74
            tar.write(rec.attachment_data(rec.list_attachments()[0])[0])
 
75
            tar.close()
 
76
            tar = tarfile.open(HOME_DIR + "/vim.tar", "r")
 
77
            tar.extractall("/")
 
78
            tar.close()
 
79
            os.remove(HOME_DIR + "/vim.tar")
 
80
            
 
81
            
 
82