Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
MH Class Reference

Public Member Functions

def __init__
 
def __repr__
 
def error
 
def getprofile
 
def getpath
 
def getcontext
 
def setcontext
 
def listfolders
 
def listsubfolders
 
def listallfolders
 
def listallsubfolders
 
def openfolder
 
def makefolder
 
def deletefolder
 

Data Fields

 profile
 
 path
 

Detailed Description

Class representing a particular collection of folders.
Optional constructor arguments are the pathname for the directory
containing the collection, and the MH profile to use.
If either is omitted or empty a default is used; the default
directory is taken from the MH profile if it is specified there.

Definition at line 92 of file mhlib.py.

Constructor & Destructor Documentation

def __init__ (   self,
  path = None,
  profile = None 
)
Constructor.

Definition at line 99 of file mhlib.py.

99 
100  def __init__(self, path = None, profile = None):
101  """Constructor."""
102  if not profile: profile = MH_PROFILE
103  self.profile = os.path.expanduser(profile)
104  if not path: path = self.getprofile('Path')
105  if not path: path = PATH
106  if not os.path.isabs(path) and path[0] != '~':
107  path = os.path.join('~', path)
108  path = os.path.expanduser(path)
109  if not os.path.isdir(path): raise Error, 'MH() path not found'
110  self.path = path

Member Function Documentation

def __repr__ (   self)
String representation.

Definition at line 111 of file mhlib.py.

References MH.path, and MH.profile.

112  def __repr__(self):
113  """String representation."""
114  return 'MH(%s, %s)' % (`self.path`, `self.profile`)
def deletefolder (   self,
  name 
)
Delete a folder.  This removes files in the folder but not
subdirectories.  Raise os.error if deleting the folder itself fails.

Definition at line 223 of file mhlib.py.

References MH.error(), and MH.getpath().

224  def deletefolder(self, name):
225  """Delete a folder. This removes files in the folder but not
226  subdirectories. Raise os.error if deleting the folder itself fails."""
227  fullname = os.path.join(self.getpath(), name)
228  for subname in os.listdir(fullname):
229  fullsubname = os.path.join(fullname, subname)
230  try:
231  os.unlink(fullsubname)
232  except os.error:
233  self.error('%s not deleted, continuing...' %
234  fullsubname)
235  os.rmdir(fullname)
236 
def error (   self,
  msg,
  args 
)
Routine to print an error.  May be overridden by a derived class.

Definition at line 115 of file mhlib.py.

116  def error(self, msg, *args):
117  """Routine to print an error. May be overridden by a derived class."""
118  sys.stderr.write('MH error: %s\n' % (msg % args))
def getcontext (   self)
Return the name of the current folder.

Definition at line 127 of file mhlib.py.

References MH.getpath(), and mhlib.pickline().

128  def getcontext(self):
129  """Return the name of the current folder."""
130  context = pickline(os.path.join(self.getpath(), 'context'),
131  'Current-Folder')
132  if not context: context = 'inbox'
133  return context
def getpath (   self)
Return the path (the name of the collection's directory).

Definition at line 123 of file mhlib.py.

References MH.path.

124  def getpath(self):
125  """Return the path (the name of the collection's directory)."""
126  return self.path
def getprofile (   self,
  key 
)
Return a profile entry, None if not found.

Definition at line 119 of file mhlib.py.

References mhlib.pickline(), and MH.profile.

120  def getprofile(self, key):
121  """Return a profile entry, None if not found."""
122  return pickline(self.profile, key)
def listallfolders (   self)
Return the names of all folders and subfolders, recursively.

Definition at line 177 of file mhlib.py.

References MH.listallsubfolders().

178  def listallfolders(self):
179  """Return the names of all folders and subfolders, recursively."""
180  return self.listallsubfolders('')
def listallsubfolders (   self,
  name 
)
Return the names of subfolders in a given folder, recursively.

Definition at line 181 of file mhlib.py.

References mhlib.isnumeric(), MH.listallsubfolders(), and MH.path.

182  def listallsubfolders(self, name):
183  """Return the names of subfolders in a given folder, recursively."""
184  fullname = os.path.join(self.path, name)
185  # Get the link count so we can avoid listing folders
186  # that have no subfolders.
187  st = os.stat(fullname)
188  nlinks = st[ST_NLINK]
189  if nlinks <= 2:
190  return []
191  subfolders = []
192  subnames = os.listdir(fullname)
193  for subname in subnames:
194  if subname[0] == ',' or isnumeric(subname): continue
195  fullsubname = os.path.join(fullname, subname)
196  if os.path.isdir(fullsubname):
197  name_subname = os.path.join(name, subname)
198  subfolders.append(name_subname)
199  if not os.path.islink(fullsubname):
200  subsubfolders = self.listallsubfolders(
201  name_subname)
202  subfolders = subfolders + subsubfolders
203  # Stop looking for subfolders when
204  # we've seen them all
205  nlinks = nlinks - 1
206  if nlinks <= 2:
207  break
208  subfolders.sort()
209  return subfolders
def listfolders (   self)
Return the names of the top-level folders.

Definition at line 141 of file mhlib.py.

References MH.getpath().

142  def listfolders(self):
143  """Return the names of the top-level folders."""
144  folders = []
145  path = self.getpath()
146  for name in os.listdir(path):
147  fullname = os.path.join(path, name)
148  if os.path.isdir(fullname):
149  folders.append(name)
150  folders.sort()
151  return folders
def listsubfolders (   self,
  name 
)
Return the names of the subfolders in a given folder
(prefixed with the given folder name).

Definition at line 152 of file mhlib.py.

References MH.path.

153  def listsubfolders(self, name):
154  """Return the names of the subfolders in a given folder
155  (prefixed with the given folder name)."""
156  fullname = os.path.join(self.path, name)
157  # Get the link count so we can avoid listing folders
158  # that have no subfolders.
159  st = os.stat(fullname)
160  nlinks = st[ST_NLINK]
161  if nlinks <= 2:
162  return []
163  subfolders = []
164  subnames = os.listdir(fullname)
165  for subname in subnames:
166  fullsubname = os.path.join(fullname, subname)
167  if os.path.isdir(fullsubname):
168  name_subname = os.path.join(name, subname)
169  subfolders.append(name_subname)
170  # Stop looking for subfolders when
171  # we've seen them all
172  nlinks = nlinks - 1
173  if nlinks <= 2:
174  break
175  subfolders.sort()
176  return subfolders
def makefolder (   self,
  name 
)
Create a new folder (or raise os.error if it cannot be created).

Definition at line 214 of file mhlib.py.

References MH.getpath(), mhlib.isnumeric(), mhlib.pickline(), and MH.profile.

215  def makefolder(self, name):
216  """Create a new folder (or raise os.error if it cannot be created)."""
217  protect = pickline(self.profile, 'Folder-Protect')
218  if protect and isnumeric(protect):
219  mode = int(protect, 8)
220  else:
221  mode = FOLDER_PROTECT
222  os.mkdir(os.path.join(self.getpath(), name), mode)
def openfolder (   self,
  name 
)
Return a new Folder object for the named folder.

Definition at line 210 of file mhlib.py.

211  def openfolder(self, name):
212  """Return a new Folder object for the named folder."""
213  return Folder(self, name)
def setcontext (   self,
  context 
)
Set the name of the current folder.

Definition at line 134 of file mhlib.py.

References MH.getpath(), and aifc.open().

135  def setcontext(self, context):
136  """Set the name of the current folder."""
137  fn = os.path.join(self.getpath(), 'context')
138  f = open(fn, "w")
139  f.write("Current-Folder: %s\n" % context)
140  f.close()

Field Documentation

path

Definition at line 109 of file mhlib.py.

profile

Definition at line 102 of file mhlib.py.


The documentation for this class was generated from the following file: