Changeset 4190 for waeup/branches


Ignore:
Timestamp:
27 May 2009, 11:57:16 (15 years ago)
Author:
uli
Message:

Use new helper function with datacenter storage settings.

Location:
waeup/branches/ulif-rewrite/src/waeup
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-rewrite/src/waeup/datacenter.py

    r4186 r4190  
    1313from zope.interface import Interface
    1414from waeup.interfaces import IWAeUPObject, IWAeUPCSVImporter, ICSVDataReceivers
     15from waeup.utils.helpers import copyFileSystemTree
    1516from waeup.viewlets import Index, MainArea, LeftSidebar
    1617
     
    7172        return result
    7273
    73     def setStoragePath(self, path, move=False):
     74    def setStoragePath(self, path, move=False, overwrite=False):
    7475        """Set the path where to store files.
    7576        """
    7677        path = os.path.abspath(path)
     78        not_copied = []
    7779        if not os.path.exists(path):
    7880            raise ValueError('The path given does not exist: %s' % path)
    7981        if move is True:
    80             # copy contents of old location to new one
    81             srcdir = self.storage
    82             dstdir = path
    83             for item in os.listdir(srcdir):
    84                 if os.path.isdir(item):
    85                     shutil.copytree(os.path.join(srcdir, item),
    86                                     os.path.join(dstdir, item))
    87                 else:
    88                     shutil.copy2(os.path.join(srcdir, item), dstdir)
     82
     83            not_copied = copyFileSystemTree(self.storage, path,
     84                                            overwrite=overwrite)
    8985       
    9086        self.storage = path
    91 
     87        return not_copied
    9288
    9389    def getCSVDataReceivers(self, obj):
     
    244240    grok.template('master')
    245241
    246     def update(self, newpath=None, save=None, cancel=None):
     242    def update(self, newpath=None, move=False, overwrite=False,
     243               save=None, cancel=None):
     244        if move:
     245            move = True
     246        if overwrite:
     247            overwrite = True
    247248        if newpath is None:
    248249            return
     
    251252            return
    252253        try:
    253             self.context.setStoragePath(newpath)
     254            not_copied = self.context.setStoragePath(newpath, move=move)
     255            for name in not_copied:
     256                self.flash('File already existed (not copied): %s' % name)
    254257        except ValueError:
    255258            self.flash('Given storage path cannot be used.')
     
    257260            return
    258261        if newpath:
     262            self.flash('New storage path succefully set.')
    259263            self.redirect(self.url(self.context))
    260264        return
  • waeup/branches/ulif-rewrite/src/waeup/datacenter_templates/settingsmain.pt

    r4153 r4190  
    77           tal:attributes="value context/storage" />
    88    <br />
     9    <div>
     10      <input type="checkbox" name="move" checked="checked" />
     11      <label for="move">Copy existing data to new storage?</label>
     12    </div>
     13    <div>
     14      <input type="checkbox" name="overwrite" checked="no" />
     15      <label for="overwrite">Overwrite contents in new location?</label>
     16    </div>
     17
    918    <input type="submit" name="save" value="Save" />
    1019    <input type="reset" name="reset" value="Reset" />
Note: See TracChangeset for help on using the changeset viewer.