1
1
#!/usr/bin/env python
2
2
# -*- coding: utf-8 -*-
9
__version__ = "$Revision$"
4
# packagesync.py - sync installed packages across several computers.
6
# Copyright 2010 Duane Hinnen, Marcos Vanetta
8
# This program is free software: you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License version 3, as published
10
# by the Free Software Foundation.
12
# This program is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranties of
14
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
# PURPOSE. See the GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License along
18
# with this program. If not, see <http://www.gnu.org/licenses/>.
14
from desktopcouch.records.server import CouchDatabase
15
from desktopcouch.records.record import Record as CouchRecord
16
22
from core.stipple import PluginBase
18
database = CouchDatabase("packages", create=True)
20
RECORD_TYPE = 'http://www.okiebuntu.homelinux.com/packagesync'
21
VIM_CONFIG = os.path.expanduser("~") + "/.vimrc"
22
23
HOME_DIR = os.path.expanduser("~")
24
VIM_CONFIG = HOME_DIR + "/.vimrc"
23
25
VIM_DIR = HOME_DIR + "/.vim"
25
26
class Plugin(PluginBase):
30
#self.vimDir = self.homePath + "/.vim"
32
self.prog_name = "vim"
33
self.record_name = self.name.lower()
33
''' get simple list of installed apps to search for config files '''
34
search_string = commands.getoutput("dpkg --get-selections '*'")
35
if search_string.find("vim") != -1:
36
''' write the vim config to a couchdb '''
37
with open(VIM_CONFIG, 'r') as vim:
42
record_four = CouchRecord({ "_id" : "vim" ,
43
"profile" : "user001" ,
47
record_type = RECORD_TYPE)
48
if os.path.exists(VIM_DIR):
49
tar = tarfile.open(HOME_DIR + "/vim.tar", "w")
52
record_four.attach(open(HOME_DIR + "/vim.tar", "r"), "vim.tar", "tarfile/tar")
53
os.remove(HOME_DIR + "/vim.tar")
54
databaserecord = database.put_record(record_four)
57
print "Bash it's not even installed SUCKER!"
36
"""It must be installed"""
37
with open(VIM_CONFIG, "r") as vim:
41
self.attachDirectory(VIM_DIR)
61
map_js2 = 'function(doc){if (doc._id == "vim"){emit(null,doc.file);}}'
62
database.add_view("vimconfig", map_js2, None, "getfile")
63
result = database.execute_view("vimconfig", "getfile")
66
config_iter = row.value
68
vim_file = open(os.path.expanduser("~") + "/.vimrc", 'w')
69
vim_file.write(config_iter)
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])
76
tar = tarfile.open(HOME_DIR + "/vim.tar", "r")
79
os.remove(HOME_DIR + "/vim.tar")
45
cad = self.recoverDotFile()
47
with open(VIM_CONFIG, "w") as vim:
50
self.recoverDirectory(VIM_DIR)