Commits

Marko Loparic  committed 7db8fbb

[structure, items, plugins] now passing config object everywhere (ugly but safe)

  • Participants
  • Parent commits 28cac02

Comments (0)

Files changed (11)

File items/item.py

 class AbstractItem(Container):
     "A sheet is composed of items"
 
-    def __init__(self, name, sheet_persister, provides=None, create=False):
+    def __init__(self, name, sheet_persister, config, provides=None,
+                 create=False):
         self.name = name
+        self._config = config
         self._persister = sheet_persister.get_subpersister(name, create=create)
         Container.__init__(self, self._persister)
 

File plugins/plantrisk_change.py

     name = 'plantrisk_change'
     title = 'PlantRisk change workbook'
 
-    def __init__(self, name, parent_container, create=False):
+    def __init__(self, name, parent_container, config, create=False):
         provides = [Resource('plantrisk_workbook_path', 'result_path')]
-        AbstractItem.__init__(self, name, parent_container,
+        AbstractItem.__init__(self, name, parent_container, config,
                               create=create, provides=provides)
 
         # first element: case name

File plugins/plantrisk_master.py

     name = 'plantrisk_master'
     title = 'PlantRisk master workbook'
 
-    def __init__(self, name, sheet_persister, create=False):
+    def __init__(self, name, sheet_persister, config, create=False):
         provides = [Resource('plantrisk_workbook_path', '_path')]
-        AbstractItem.__init__(self, name, sheet_persister,
+        AbstractItem.__init__(self, name, sheet_persister, config,
                               create=create, provides=provides)
 
         # first element is the case

File plugins/shell_no_cancel.py

     name = 'shell_no_cancel'
     title = u'Shell no cancel'
 
-    def __init__(self, name, sheet_persister, create=False):
-        AbstractItem.__init__(self, name, sheet_persister, create=create)
+    def __init__(self, name, sheet_persister, config, create=False):
+        AbstractItem.__init__(self, name, sheet_persister, config,
+                              create=create)
 
         # first element is the command
         self._cmd_str = PersistentObject()

File plugins/shell_with_cancel.py

     name = 'shell_with_cancel'
     title = 'Shell with cancel'
 
-    def __init__(self, name, parent_container, create=False):
-        AbstractItem.__init__(self, name, parent_container, create=create)
+    def __init__(self, name, parent_container, config, create=False):
+        AbstractItem.__init__(self, name, parent_container, config,
+                              create=create)
 
         # first element is the command box
         self._cmd_str = PersistentObject()

File plugins/upper_case.py

     name = 'upper_case'
     title = u'Upper case'
 
-    def __init__(self, name, sheet_persister, create=False):
+    def __init__(self, name, sheet_persister, config, create=False):
         # When this code was first written the objects didn't have to be
         # replicated like they are now. Before, the persistence was made 
         # partly in the element, so the same object communicating with the
         # - This new design seems ugly for this item, but for more complex 
         #   items it will imply a cleared, more explicit code
 
-        AbstractItem.__init__(self, name, sheet_persister, create=create)
+        AbstractItem.__init__(self, name, sheet_persister, config,
+                              create=create)
         self._entered_text = PersistentObject()
         self._formatted_text = PersistentObject()
         self._entered_box = TextBox('entered_box', "Entered text", 

File structure/book.py

 SHEET_NAME = 'sheet'
 
 class Book(Container):
-    def __init__(self, name, parent_persister, create=False, title=None):
+    def __init__(self, name, parent_persister, config, create=False,
+                 title=None):
         self.name = name
+        self._config = config
         self._persister = parent_persister.get_subpersister(name, create=create)
         Container.__init__(self, self._persister)
         self.logger = get_module_logger()
         # XXX: for the moment each book has a single sheet (use the same
         # title as the book)
         if create:
-            self.sheet = Sheet(SHEET_NAME, self._persister, create=True, 
-                               title=self.title)
+            self.sheet = Sheet(SHEET_NAME, self._persister, self._config,
+                               create=True, title=self.title)
         else:
-            self.sheet = Sheet(SHEET_NAME, self._persister, create=False)
+            self.sheet = Sheet(SHEET_NAME, self._persister, self._config,
+                               create=False)

File structure/book_tree.py

 BOOK_NAME_PREFIX = 'book_'
 
 class BookTree(Container):
-    def __init__(self, name, parent_persister, create=False, data_dir=None):
+    def __init__(self, name, parent_persister, config, create=False,
+                 data_dir=None):
         self.name = name
+        self._config = config
         if parent_persister is None:
             if data_dir is None:
                 raise ValueError("a data_dir must be given if no parent "
             self._persister = FlexiblePersister(name, create=create, 
                                                 data_dir=data_dir)
         else:
-            self._persister = parent_persister.get_subpersister(name, create=create)
+            self._persister = parent_persister.get_subpersister(
+                name, create=create)
         Container.__init__(self, self._persister)
         self.logger = get_module_logger()
 
 
         self.books = []
         for name in self._book_names:
-            book = Book(name, self._persister)
+            book = Book(name, self._persister, self._config)
             self.books.append(book)
 
     def add_book(self, title):
         self._check_title_duplication(title)
         name = compute_random_name(BOOK_NAME_PREFIX, self._book_names)
         self._book_names.append(name)
-        book = Book(name, self._persister, create=True, title=title)
+        book = Book(name, self._persister, self._config, create=True,
+                    title=title)
         self.books.append(book)
 
     def _check_title_duplication(self, title):

File structure/sheet.py

 import limma.plugins  # pylint: disable=W0611
 
 class Sheet(Container):
-    def __init__(self, name, parent_persister, create=False, title=None):
+    def __init__(self, name, parent_persister, config, create=False,
+                 title=None):
         self.name = name
+        self._config = config
         self._persister = parent_persister.get_subpersister(name, create=create)
         Container.__init__(self, self._persister)
         self.logger = get_module_logger()
             self.title = title
 
         # build items, possibly already persisted
-        self._item_struct = SheetItemStruct(self._persister)
+        self._item_struct = SheetItemStruct(self._persister, self._config)
         
         # the attributes of the sheet to be persisted
         # - for the moment the sheet is defined only by the cursor
             if name in names:
                 raise ValueError("item '%s' already exists")
         
-        item = item_type(name, self._persister, create=True)
+        item = item_type(name, self._persister, self._config, create=True)
         self._item_struct.add(item, item_type, index=index)
         
         # cursor can't remain after an edited item
 
     - avoiding __len__, __getitem__, etc for the moment...
     """
-    def __init__(self, persister):
+    def __init__(self, persister, config):
         # using the same persiser as the sheet
         self._persister = persister
         Container.__init__(self, self._persister)
             else:
                 raise TypeError("Can't find item type of name %s" 
                                 % item_type_name)
-            item = item_type(name, self._persister)
+            item = item_type(name, self._persister, config)
             self.list.append(item)
 
     def add(self, item, item_type, index=None):

File structure/structure.py

 
 class Structure(object):
     """Will be replaced by book and book tree later"""
-    def __init__(self, conf):
-        data_dir = conf[('main', 'data_directory')]
+    def __init__(self, config):
+        data_dir = config['data_directory']
 
         # normally the code knows whether it expects to find data or not. This 
         # the only exception: the top level data can be there or not.
             create = False
         else:
             create = True
-        self.book_tree = BookTree('book_tree', None, create=create, 
+        self.book_tree = BookTree('book_tree', None, config, create=create, 
                                   data_dir=data_dir)

File ui/console/console_ui.py

 class ConsoleUI(AbstractUI):
     """console ui (for while the qt ui is not written, perhaps
     even for ensuring good modularity later"""
-    def __init__(self, conf):
-        AbstractUI.__init__(self, conf)
-        struct = Structure(conf)
+    def __init__(self, config):
+        AbstractUI.__init__(self, config)
+        struct = Structure(config)
         self._book_tree = struct.book_tree
         self._sheet = None  # sheet shown at the moment