~aw/rhythmbox-swedishradio/trunk

« back to all changes in this revision

Viewing changes to plugins/zshrc.py

  • Committer: duanedesign
  • Date: 2010-06-09 13:26:34 UTC
  • Revision ID: duanedesign@gmail.com-20100609132634-l5no42pskpm92kf7
new merge from stipple-devs/+junk/stipple-sensitive with a few small bug fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# -*- coding: utf-8 -*-
3
 
 
4
 
"""DocString
5
 
 
6
 
DocString Paragraph
7
 
 
8
 
"""
9
 
 
10
 
__version__ = "$Revision$"
11
 
 
12
 
import os
13
 
import commands
14
 
from desktopcouch.records.server import CouchDatabase
15
 
from desktopcouch.records.record import Record as CouchRecord
16
 
from core.stipple import PluginBase
17
 
 
18
 
database = CouchDatabase("packages", create=True)
19
 
databaserecord = ""
20
 
RECORD_TYPE = 'http://www.okiebuntu.homelinux.com/packagesync'
21
 
ZSH_CONFIG = os.path.expanduser("~") + "/.zshrc"
22
 
 
23
 
class Plugin(PluginBase):
24
 
    def __init__(self):
25
 
        self.name = "Zshrc"
26
 
        self.icon = None
27
 
 
28
 
    def sync(self):
29
 
        ''' get simple list of installed apps to search for config files '''
30
 
        search_string = commands.getoutput("dpkg --get-selections '*'")
31
 
        if search_string.find("zsh") != -1:
32
 
            ''' write the zsh config to a couchdb '''
33
 
            with open(ZSH_CONFIG, 'r') as zsh:
34
 
                zr = zsh.read()
35
 
            print zr
36
 
 
37
 
 
38
 
            record_five = CouchRecord({  "_id"       :  "zsh"   ,  
39
 
                                        "profile"   :  "user001" ,
40
 
                                        "type"      :  "dotfile" ,
41
 
                                        "file"      :  zr        ,
42
 
                                     },
43
 
                                     record_type = RECORD_TYPE)
44
 
 
45
 
            databaserecord = database.put_record(record_five)
46
 
            zsh.close()
47
 
        else:
48
 
            print "Zsh is not installed SUCKER!"
49
 
            return
50
 
 
51
 
    def restore(self):
52
 
        map_js2 = 'function(doc){if (doc._id == "zsh"){emit(null,doc.file);}}'
53
 
        database.add_view("zshconfig", map_js2, None, "getfile")
54
 
        result = database.execute_view("zshconfig", "getfile")
55
 
 
56
 
        for row in result:
57
 
            config_iter = row.value
58
 
 
59
 
        zsh_file = open(os.path.expanduser("~") + "/.zshrc2", 'w')
60
 
        zsh_file.write(config_iter)
61
 
        zsh_file.close() 
62