File: basefile.py

package info (click to toggle)
python-wikkid 0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 728 kB
  • sloc: python: 3,051; makefile: 12
file content (30 lines) | stat: -rw-r--r-- 790 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#
# Copyright (C) 2010 Wikkid Developers.
#
# This software is licensed under the GNU Affero General Public License
# version 3 (see the file LICENSE).

"""Base classes for other filestores to use."""

import mimetypes

import breezy.urlutils as urlutils

from wikkid.interface.filestore import FileType


class BaseFile(object):
    """Provide common fields and methods and properties for files."""

    def __init__(self, path):
        self.path = path
        self.base_name = urlutils.basename(path)
        self._mimetype = mimetypes.guess_type(self.base_name)[0]

    @property
    def mimetype(self):
        """If the file_type is a directory, return None."""
        if self.file_type == FileType.DIRECTORY:
            return None
        else:
            return self._mimetype