~ubuntu-branches/ubuntu/natty/pida/natty

« back to all changes in this revision

Viewing changes to pida/core/document.py

  • Committer: Bazaar Package Importer
  • Author(s): Jan Luebbe
  • Date: 2007-09-05 17:54:09 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070905175409-ty9f6qpuctyjv1sd
Tags: 0.5.1-2
* Depend on librsvg2-common, which is not pulled in by the other depends
  (closes: #394860)
* gvim is no alternative for python-gnome2 and python-gnome2-extras
  (closes: #436431)
* Pida now uses ~/.pida2, so it can no longer be confused by old
  configurations (closes: #421378)
* Culebra is no longer supported by upstream (closes: #349009)
* Update manpage (closes: #440375)
* Update watchfile (pida is now called PIDA)

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
import actions
35
35
 
36
 
 
37
 
class document_handler(actions.action_handler):
 
36
# locale
 
37
from pida.core.locale import Locale
 
38
locale = Locale('pida')
 
39
_ = locale.gettext
 
40
 
 
41
 
 
42
class document_handler(object):
38
43
    
39
44
    globs = []
40
45
    type_name = 'document'
57
62
    """
58
63
 
59
64
    if not os.path.exists(target):
60
 
        raise OSError, 'Target does not exist: '+target
 
65
        raise OSError, _('Target does not exist: ')+target
61
66
 
62
67
    if not os.path.isdir(basepath):
63
 
        raise OSError, 'Base is not a directory or does not exist: '+basepath
 
68
        raise OSError, _('Base is not a directory or does not exist: ')+basepath
64
69
 
65
70
    base_list = (os.path.abspath(basepath)).split(os.sep)
66
71
    target_list = (os.path.abspath(target)).split(os.sep)
68
73
    # On the windows platform the target may be on a completely different
69
74
    # drive from the base.
70
75
    if os.name in ['nt', 'dos', 'os2'] and base_list[0] != target_list[0]:
71
 
        msg = 'Target is on a different drive to base. Target: %s, base: %s'
72
 
        msg %= (target_list[0].upper(), base_list[0].upper())
 
76
        msg = _('Target is on a different drive to base. Target: %(target)s, base: %(base)s')
 
77
        msg %= {target:target_list[0].upper(), base:base_list[0].upper()}
73
78
        raise OSError(msg)
74
79
 
75
80
    # Starting from the filepath root, work out how much of the filepath is
94
99
new_file_index = 1
95
100
 
96
101
 
97
 
class document(base.pidacomponent):
 
102
class Document(object):
98
103
    """Base document class."""
99
104
    """A real file on disk."""
100
105
    icon_name = 'new'
106
111
    markup_string = ('<span color="#600060">'
107
112
                     '%(project_name)s</span><tt>:</tt>'
108
113
                     '<span color="%(directory_colour)s">'
109
 
                     '%(project_relative_path)s</span>'
 
114
                     '%(project_relative_path)s/</span>'
110
115
                     '<b>%(basename)s</b>')
111
116
    contexts = []
112
117
    is_new = False
113
118
 
114
 
    def __init__(self, filename=None,
 
119
    def __init__(self, boss, filename=None,
115
120
                       markup_attributes=None,
116
121
                       markup_string=None,
117
122
                       contexts=None,
118
123
                       icon_name=None,
119
124
                       handler=None,
120
125
                       detect_encoding=DETECTOR_MANAGER):
 
126
        self.boss = boss
121
127
        self.__handler = handler
122
128
        self.__filename = filename
123
129
        self.__unique_id = time.time()
124
130
        self.__project = None
125
131
        self.__newfile_index = None
126
132
        self.__detect_encoding = detect_encoding
 
133
 
 
134
        self.creation_time = time.time()
127
135
        
128
136
        if filename is None:
129
137
            global new_file_index
133
141
            self.markup_attributes = markup_attributes
134
142
        if markup_string is not None:
135
143
            self.markup_string = markup_string
136
 
        base.pidacomponent.__init__(self)
137
 
                     
138
 
    def init(self):
 
144
        self.project, self.project_relative_path = self.get_project_relative_path()
139
145
        self.__reset()
140
146
 
141
147
    def __reset(self):
184
190
            self.__string = None
185
191
            raise
186
192
            # Also warn the log about it
187
 
            self.log.warn('failed to open file %s', self.filename)
 
193
            self.log.warn(_('failed to open file %s'), self.filename)
188
194
            
189
195
        
190
196
    def __load_stat(self):
229
235
 
230
236
    stat = property(__get_stat)
231
237
 
 
238
    def get_mtime(self):
 
239
        return self.stat[stat.ST_MTIME]
 
240
 
 
241
    modified_time = property(get_mtime)
 
242
 
 
243
    def get_size(self):
 
244
        return self.stat[stat.ST_SIZE]
 
245
 
 
246
    size = property(get_size)
 
247
 
232
248
    def __get_mimetype(self):
233
249
        return self.__mimetype
234
250
 
313
329
    handler = property(get_handler)
314
330
 
315
331
    def get_project_name(self):
316
 
        if self.__project:
317
 
            return self.__project.general__name
 
332
        if self.project is not None:
 
333
            return self.project.get_display_name()
318
334
        else:
319
335
            return ''
320
336
    project_name = property(get_project_name)
321
337
 
322
338
    def get_project_relative_path(self):
323
 
        if self.__project:
324
 
            return relpath(self.filename, self.__project.source__directory)
 
339
        match = self.boss.cmd('project', 'get_project_for_document', document=self)
 
340
        if match is None:
 
341
            return None, os.sep.join(self.directory.split(os.path.sep)[-2:])
325
342
        else:
326
 
            return os.path.join(self.directory_basename, '')
327
 
 
328
 
    project_relative_path = property(get_project_relative_path)
 
343
            project, path = match
 
344
            return project, path
329
345
    
330
346
    def set_project(self, project):
331
347
        self.__project = project
388
404
    unittest.main()
389
405
    
390
406
        
391
 
class realfile_document(document):
392
 
    """Real file"""
393
 
 
394
407
 
395
408