~singlet-developers/singlet/0.2

« back to all changes in this revision

Viewing changes to src/singlet/utils.py

  • Committer: Michael Hall
  • Date: 2012-03-14 15:34:12 UTC
  • Revision ID: mhall119@ubuntu.com-20120314153412-o2q34gnex5xgn6xs
Remove utils functions that now reside in the quickly template, making Singlet now a runtime-only library

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
import singlet
27
27
 
28
 
def run_scope(scope_class, args=None):
29
 
    if args and len(args) > 1 and args[1] == 'make':
30
 
        build_scope_files(scope_class, args)
31
 
    elif args and len(args) > 1 and args[1] == 'install':
32
 
        install_scope_files(scope_class, args)
33
 
    #elif args and len(args) > 1 and args[1] == 'uninstall':
34
 
        #uninstall_lens_files(lens_class, args)
35
 
    #elif args and len(args) > 1 and args[1] == 'package':
36
 
        #build_package_files(lens_class, args)
37
 
    #elif args and len(args) > 1 and args[1] == 'release':
38
 
        #build_release_files(lens_class, args)
39
 
    else:
40
 
        run_scope_daemon(scope_class)
41
 
 
42
28
def run_lens(lens_class, args=None):
43
 
    if args and len(args) > 1 and args[1] == 'make':
44
 
        build_lens_files(lens_class, args)
45
 
    elif args and len(args) > 1 and args[1] == 'install':
46
 
        install_lens_files(lens_class, args)
47
 
    elif args and len(args) > 1 and args[1] == 'uninstall':
48
 
        uninstall_lens_files(lens_class, args)
49
 
    elif args and len(args) > 1 and args[1] == 'package':
50
 
        build_package_files(lens_class, args)
51
 
    elif args and len(args) > 1 and args[1] == 'release':
52
 
        build_release_files(lens_class, args)
53
 
    else:
54
 
        run_lens_daemon(lens_class)
55
 
 
56
 
def build_lens_files(lens_class, args):
57
 
    service_file = open('./unity-%s-lens.service' % lens_class._meta.name, 'w')
58
 
    service_file.write('''[D-BUS Service]
59
 
Name=%s
60
 
Exec=/usr/lib/singlet/%s
61
 
''' % (lens_class._meta.bus_name, args[0]))
62
 
    service_file.close()
63
 
 
64
 
    lens_file = open('./%s.lens' % lens_class._meta.name, 'w')
65
 
    lens_file.write('''[Lens]
66
 
DBusName=%(bus_name)s
67
 
DBusPath=%(bus_path)s
68
 
Name=%(title)s
69
 
Icon=/usr/share/unity/lenses/%(name)s/%(icon_name)s
70
 
Description=%(description)s
71
 
SearchHint=%(search_hint)s
72
 
#Shortcut=c
73
 
 
74
 
[Desktop Entry]
75
 
X-Ubuntu-Gettext-Domain=%(name)s
76
 
''' % {
77
 
        'name': lens_class._meta.name,
78
 
        'title': lens_class._meta.title,
79
 
        'description': lens_class._meta.description,
80
 
        'search_hint': lens_class._meta.search_hint,
81
 
        'icon_name': os.path.basename(lens_class._meta.icon),
82
 
        'bus_path': lens_class._meta.bus_path,
83
 
        'bus_name': lens_class._meta.bus_name })
84
 
    lens_file.close()
85
 
 
86
 
def build_scope_files(scope_class, args):
87
 
    service_file = open('./unity-%s-scope.service' % scope_class._meta.name, 'w')
88
 
    service_file.write('''[D-BUS Service]
89
 
Name=%s
90
 
Exec=/usr/lib/singlet/%s
91
 
''' % (scope_class._meta.bus_name, args[0]))
92
 
    service_file.close()
93
 
 
94
 
    scope_file = open('./%s.scope' % scope_class._meta.name, 'w')
95
 
    scope_file.write('''[Scope]
96
 
DBusName=%(bus_name)s
97
 
DBusPath=%(bus_path)s
98
 
Name=%(title)s
99
 
Description=%(description)s
100
 
 
101
 
[Desktop Entry]
102
 
X-Ubuntu-Gettext-Domain=%(name)s
103
 
''' % {
104
 
        'name': scope_class._meta.name,
105
 
        'title': scope_class._meta.title,
106
 
        'description': scope_class._meta.description,
107
 
        'bus_path': scope_class._meta.bus_path,
108
 
        'bus_name': scope_class._meta.bus_name })
109
 
    scope_file.close()
110
 
 
111
 
def install_lens_files(lens_class, args):
112
 
    if not os.path.exists('/usr/share/unity/lenses/%s' % lens_class._meta.name):
113
 
        os.mkdir('/usr/share/unity/lenses/%s' % lens_class._meta.name)
114
 
    shutil.copy('./unity-%s-lens.service' % lens_class._meta.name, '/usr/share/dbus-1/services/')
115
 
    shutil.copy('./%s.lens' % lens_class._meta.name, '/usr/share/unity/lenses/%s' % lens_class._meta.name)
116
 
    shutil.copy(lens_class._meta.icon, '/usr/share/unity/lenses/%s' % lens_class._meta.name)
117
 
 
118
 
    if not os.path.exists('/usr/lib/singlet'):
119
 
        os.mkdir('/usr/lib/singlet')
120
 
    shutil.copy(args[0], '/usr/lib/singlet/')
121
 
    
122
 
def uninstall_lens_files(lens_class, args):
123
 
    os.remove(os.path.join('/usr/share/dbus-1/services/', 'unity-%s-lens.service' % lens_class._meta.name))
124
 
    os.remove(os.path.join('/usr/share/unity/lenses/%s' % lens_class._meta.name, '%s.lens' % lens_class._meta.name))
125
 
    os.remove(os.path.join('/usr/share/unity/lenses/%s' % lens_class._meta.name, os.path.basename(lens_class._meta.icon)))
126
 
    os.rmdir('/usr/share/unity/lenses/%s' % lens_class._meta.name)
127
 
    
128
 
    os.remove(os.path.join('/usr/lib/singlet/', args[0]))
129
 
 
130
 
def install_scope_files(scope_class, args):
131
 
    if not os.path.exists('/usr/share/unity/lenses/%s' % scope_class._meta.lens_name):
132
 
        os.mkdir('/usr/share/unity/lenses/%s' % scope_class._meta.lens_name)
133
 
    shutil.copy('./unity-%s-scope.service' % scope_class._meta.name, '/usr/share/dbus-1/services/')
134
 
    shutil.copy('./%s.scope' % scope_class._meta.name, '/usr/share/unity/lenses/%s' % scope_class._meta.lens_name)
135
 
 
136
 
    if not os.path.exists('/usr/lib/singlet'):
137
 
        os.mkdir('/usr/lib/singlet')
138
 
    shutil.copy(args[0], '/usr/lib/singlet/')
139
 
    
140
 
def uninstall_scope_files(scope_class, args):
141
 
    os.remove(os.path.join('/usr/share/dbus-1/services/', 'unity-%s-scope.service' % scope_class._meta.lens_name))
142
 
    os.remove(os.path.join('/usr/share/unity/lenses/%s' % scope_class._meta.lens_name, '%s.scope' % scope_class._meta.name))
143
 
    
144
 
    os.remove(os.path.join('/usr/lib/singlet/', args[0]))
145
 
 
146
 
def build_package_files(lens_class, args):
147
 
    setup_file = open('./setup.py', 'w')
148
 
    setup_file.write('''#!/usr/bin/env python
149
 
 
150
 
from distutils.core import setup
151
 
 
152
 
setup(name='unity-%(name)s-lens',
153
 
    version='0.1',
154
 
    description='%(description)s',
155
 
    author='%(debfullname)s',
156
 
    author_email='%(debemail)s',
157
 
    license='GPLv3',
158
 
    url='http://launchpad.net/singlet',
159
 
    #requires=['unity-singlet (>=%(version)s)'],
160
 
)
161
 
''' % {
162
 
        'name': lens_class._meta.name,
163
 
        'description': lens_class._meta.description,
164
 
        'debfullname': os.environ.get('DEBFULLNAME', 'Add your name here'),
165
 
        'debemail': os.environ.get('DEBEMAIL', 'Add your email here'),
166
 
        'version': singlet.__version__})
167
 
    setup_file.close()
168
 
 
169
 
    subprocess.call(['python-mkdebian','--dependency=unity-singlet (>= %s)' % singlet.__version__,'--dependency=unity'])
170
 
 
171
 
def release_package_files(lens_class, args):
172
 
    pass
173
 
 
174
 
def run_lens_daemon(lens_class):
175
29
    session_bus_connection = Gio.bus_get_sync (Gio.BusType.SESSION, None)
176
30
    session_bus = Gio.DBusProxy.new_sync (session_bus_connection, 0, None,
177
31
                                          'org.freedesktop.DBus',
191
45
    lens = lens_class()
192
46
    GObject.MainLoop().run()        
193
47
 
194
 
def run_scope_daemon(scope_class):
 
48
def run_scope(scope_class, args=None):
195
49
    session_bus_connection = Gio.bus_get_sync (Gio.BusType.SESSION, None)
196
50
    session_bus = Gio.DBusProxy.new_sync (session_bus_connection, 0, None,
197
51
                                          'org.freedesktop.DBus',