~marcosvanetta/stipple/stipple-new-pluginbase

« back to all changes in this revision

Viewing changes to core/app.py

  • Committer: duanedesign
  • Date: 2010-04-29 05:12:26 UTC
  • Revision ID: duanedesign@gmail.com-20100429051226-q1nq3guynz92ci4t
split the code into multiple files app,db,gui

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- coding: utf-8 -*-
 
3
#
 
4
# packagesync.py - sync installed packages across several computers.
 
5
#
 
6
# Copyright 2010 Duane Hinnen
 
7
#
 
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.
 
11
#
 
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.
 
16
#
 
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/>.
 
19
#
 
20
'''
 
21
Main Program
 
22
Uses Ubuntu-one to sync different stuff
 
23
https://wiki.ubuntu.com/OneConf
 
24
'''
 
25
 
 
26
import commands
 
27
from core.gui import Window
 
28
 
 
29
class Stipple(object):
 
30
    def UseSettings(self):
 
31
        '''
 
32
        Create a View. Execute view. Iterate over it.
 
33
        Write the package selections to a tmp file.
 
34
        Use file to set selections and then intall the packages
 
35
        '''
 
36
        map_js = 'function(doc){if (doc._id == "deb"){emit(null,doc.packages);}}'
 
37
        database.add_view("installed", map_js, None, "getnames")
 
38
        result = database.execute_view("installed", "getnames")
 
39
 
 
40
        for row in result:
 
41
            dpkglist = row.value
 
42
        
 
43
        tmp_file = open('/tmp/workfile', 'w')
 
44
        tmp_file.write(dpkglist)
 
45
        os.system ("sudo dpkg --set-selections < /tmp/workfile")
 
46
        os.system ("sudo apt-get -y update")
 
47
        os.system ("sudo apt-get dselect-upgrade")
 
48
        tmp_file.close()
 
49
 
 
50
 
 
51
    def UseConfig(self):
 
52
        '''
 
53
        Create a View. Execute view. Iterate over it.
 
54
        Write the data to a .config in users ~/
 
55
        '''
 
56
    #    config_iter = ""
 
57
    ### emacs ###
 
58
        map_js2 = 'function(doc){if (doc._id == "emacs"){emit(null,doc.file);}}'
 
59
        database.add_view("emacsconfig", map_js2, None, "getfile")
 
60
        result = database.execute_view("emacsconfig", "getfile")
 
61
 
 
62
        for row in result:
 
63
            config_iter = row.value
 
64
            print config_iter
 
65
        emacs_file = open(os.path.expanduser("~") + "/.emacs2", 'w')
 
66
        emacs_file.write(config_iter)
 
67
        emacs_file.close()
 
68
 
 
69
    ### vim ####
 
70
        map_js2 = 'function(doc){if (doc._id == "vim"){emit(null,doc.file);}}'
 
71
        database.add_view("vimconfig", map_js2, None, "getfile")
 
72
        result = database.execute_view("vimconfig", "getfile")
 
73
 
 
74
        for row in result:
 
75
            config_iter = row.value
 
76
 
 
77
        vim_file = open(os.path.expanduser("~") + "/.vimrc2", 'w')
 
78
        vim_file.write(config_iter)
 
79
        vim_file.close()
 
80
 
 
81
    ### bash ####
 
82
        map_js2 = 'function(doc){if (doc._id == "bash"){emit(null,doc.file);}}'
 
83
        database.add_view("bashconfig", map_js2, None, "getfile")
 
84
        result = database.execute_view("bashconfig", "getfile")
 
85
 
 
86
        for row in result:
 
87
            config_iter = row.value
 
88
 
 
89
        bash_file = open(os.path.expanduser("~") + "/.bashrc2", 'w')
 
90
        bash_file.write(config_iter)
 
91
        bash_file.close()
 
92
 
 
93
    ### zsh ####
 
94
        map_js2 = 'function(doc){if (doc._id == "zsh"){emit(null,doc.file);}}'
 
95
        database.add_view("zshconfig", map_js2, None, "getfile")
 
96
        result = database.execute_view("zshconfig", "getfile")
 
97
 
 
98
        for row in result:
 
99
            config_iter = row.value
 
100
 
 
101
        zsh_file = open(os.path.expanduser("~") + "/.zshrc2", 'w')
 
102
        zsh_file.write(config_iter)
 
103
        zsh_file.close()   
 
104
 
 
105
 
 
106
def run():
 
107
    window = Window()
 
108
    window.main()
 
109
 
 
110
if __name__ == "__main__":
 
111
    print __doc__