~lidaobing/ubuntu-tweak/ubuntu-ubuntu-tweak

« back to all changes in this revision

Viewing changes to ubuntutweak/modules/scripts.py

  • Committer: LI Daobing
  • Date: 2010-07-31 10:10:26 UTC
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: lidaobing@gmail.com-20100731101026-9o3m59258q5perbo
Tags: upstream-0.5.5
ImportĀ upstreamĀ versionĀ 0.5.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
 
# Ubuntu Tweak - PyGTK based desktop configure tool
 
3
# Ubuntu Tweak - PyGTK based desktop configuration tool
4
4
#
5
5
# Copyright (C) 2007-2008 TualatriX <tualatrix@gmail.com>
6
6
#
27
27
import gobject
28
28
import gettext
29
29
import gnomevfs
 
30
import logging
30
31
from ubuntutweak.modules  import TweakModule
31
 
from ubuntutweak.common.consts import *
 
32
from ubuntutweak.common.consts import DATA_DIR, CONFIG_ROOT
32
33
from ubuntutweak.common.utils import get_icon_with_type
33
34
from ubuntutweak.widgets import DirView, FlatView
34
35
from ubuntutweak.widgets.dialogs import WarningDialog
35
36
 
 
37
log = logging.getLogger('Script')
 
38
 
36
39
(
37
40
    COLUMN_ICON,
38
41
    COLUMN_TITLE,
41
44
) = range(4)
42
45
 
43
46
class AbstractScripts:
44
 
    systemdir = os.path.join(os.path.expanduser('~'), '.ubuntu-tweak/scripts')
45
 
    userdir = os.path.join(os.getenv('HOME'), '.gnome2', 'nautilus-scripts')
 
47
    system_dir = os.path.join(CONFIG_ROOT, 'scripts')
 
48
 
 
49
    #TODO maybe remove these code in the future
 
50
    old_system_dir = os.path.join(os.path.expanduser('~'), '.ubuntu-tweak/scripts')
 
51
    if os.path.exists(old_system_dir) and not os.path.exists(system_dir):
 
52
        log.debug('Move the old_system_dir to new system_dir')
 
53
        shutil.move(old_system_dir, system_dir)
 
54
 
 
55
    user_dir = os.path.join(os.getenv('HOME'), '.gnome2', 'nautilus-scripts')
46
56
 
47
57
class DefaultScripts(AbstractScripts):
48
58
    '''This class use to create the default scripts'''
53
63
            'copy-to-download': _('Copy to Download'),
54
64
            'copy-to-home': _('Copy to Home'),
55
65
            'check-md5-sum': _('Check md5 sum'),
 
66
            'compress-pdf': _('Compress PDF'),
56
67
            'move-to': _('Move to ...'),
57
68
            'move-to-desktop': _('Move to Desktop'),
58
69
            'move-to-download': _('Move to Download'),
59
70
            'move-to-home': _('Move to Home'),
 
71
            'hardlink-to': _('Create hardlink to ...'),
60
72
            'link-to': _('Link to ...'),
61
73
            'link-to-desktop': _('Link to Desktop'),
62
74
            'link-to-download': _('Link to Download'),
73
85
            }
74
86
 
75
87
    def create(self):
76
 
        if not os.path.exists(self.systemdir):
77
 
            os.makedirs(self.systemdir)
 
88
        if not os.path.exists(self.system_dir):
 
89
            os.makedirs(self.system_dir)
78
90
        for file, des in self.scripts.items():
79
91
            realname = '%s' % des
80
 
            if not os.path.exists(os.path.join(self.systemdir,realname)):
81
 
                shutil.copy(os.path.join(DATA_DIR, 'scripts/%s' % file), os.path.join(self.systemdir,realname))
 
92
            if not os.path.exists(os.path.join(self.system_dir,realname)):
 
93
                shutil.copy(os.path.join(DATA_DIR, 'scripts/%s' % file), os.path.join(self.system_dir,realname))
82
94
 
83
95
    def remove(self):
84
 
        if not os.path.exists(self.systemdir):
 
96
        if not os.path.exists(self.system_dir):
85
97
            return 
86
 
        if os.path.isdir(self.systemdir): 
87
 
            for root, dirs, files in os.walk(self.systemdir, topdown=False):
 
98
        if os.path.isdir(self.system_dir):
 
99
            for root, dirs, files in os.walk(self.system_dir, topdown=False):
88
100
                for name in files:
89
101
                    os.remove(os.path.join(root, name))
90
102
                for name in dirs:
91
103
                    os.rmdir(os.path.join(root, name))
92
 
                    os.rmdir(self.systemdir)
 
104
                    os.rmdir(self.system_dir)
93
105
        else:
94
 
            os.unlink(self.systemdir)
 
106
            os.unlink(self.system_dir)
95
107
        return
96
108
 
97
109
class EnableScripts(DirView, AbstractScripts):
99
111
    type = _('Enabled Scripts')
100
112
 
101
113
    def __init__(self):
102
 
        DirView.__init__(self, self.userdir)
 
114
        DirView.__init__(self, self.user_dir)
103
115
 
104
116
    def do_update_model(self, dir, iter):
105
117
        for item in os.listdir(dir):
127
139
    type = _('Disabled Scripts')
128
140
 
129
141
    def __init__(self):
130
 
        FlatView.__init__(self, self.systemdir, self.userdir)
 
142
        FlatView.__init__(self, self.system_dir, self.user_dir)
131
143
 
132
144
class Scripts(TweakModule, AbstractScripts):
133
145
    __title__  = _('Manage Scripts')
134
 
    __desc__  = _("You can do all kinds of tasks with scripts.\nYou can drag and drop from File Manager.\n'Scripts' will be added to the context menu.")
 
146
    __desc__  = _("Scripts can be used to complete all kinds of tasks.\n"
 
147
                  "You can drag and drop scripts from File Manager.\n"
 
148
                  "'Scripts' will then be added to the context menu.")
135
149
    __icon__ = 'text-x-script'
136
150
    __category__ = 'personal'
 
151
    __desktop__ = ['gnome', 'une']
137
152
 
138
153
    def __init__(self):
139
154
        TweakModule.__init__(self)
187
202
        dialog.destroy()
188
203
 
189
204
    def config_test(self):
190
 
        if not os.path.exists(self.systemdir):
 
205
        if not os.path.exists(self.system_dir):
191
206
            self.default.create()