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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
""" Classes used to represent packages. """
# Standard library imports.
from os.path import join
# Enthought library imports.
from enthought.io.api import File
from enthought.traits.api import Instance, List, Str
# Local imports.
from namespace import Namespace
class Package(Namespace):
""" A package. """
#### 'Package' interface ##################################################
# The namespace that the package is defined in.
#
# fixme: This is always None for packages so why should we have this trait!
# If I remember correctly it is something to do with trait identification!
namespace = Instance(Namespace)
# The package contents (modules and sub-packages).
contents = List
# The absolute filename of the package.
filename = Str
# The package name.
name = Str
# The package's parent package (None if this is a top level package).
parent = Instance('Package')
###########################################################################
# 'Package' interface.
###########################################################################
def create_sub_package(self, name):
""" Creates a sub-package with the specified name. """
sub_package = File(join(self.filename, name))
sub_package.create_package()
return
def delete_sub_package(self, name):
""" Deletes the sub-package with the specified name. """
sub_package = File(join(self.filename, name))
sub_package.delete()
return
###########################################################################
# Private interface
###########################################################################
def _name_changed(self, name):
""" Called when the package name has been changed. """
##print '**** Package name changed', self.name
return
#### EOF ######################################################################
|