Implement copyTree in filesystem-shim

1.3
IceArmy 2011-09-04 22:07:17 -07:00
parent afe59b87dc
commit bb1a6fa838
4 changed files with 23 additions and 11 deletions

View File

@ -102,6 +102,18 @@ window.fs.copy = function (source, destination) {
} }
}; };
/** Copy a directory tree.
* It will throw an exception if it fails.
*
* @param source Path of the source directory tree
* @param destination Path of the destination directory tree
*/
window.fs.copyTree = function (source, destination) {
if (!fs._copyTree(source, destination)) {
throw "Unable to copy directory tree '" + source + "' at '" + destination + "'";
}
};
/** Move a file. /** Move a file.
* It will throw an exception if it fails. * It will throw an exception if it fails.
* *

View File

@ -174,6 +174,15 @@ class FileSystem(QObject):
# Directories # Directories
## ##
@pyqtSlot(str, str, result=bool)
def _copyTree(self, source, target):
try:
shutil.copytree(source, target)
return True
except IOError as (t, e):
qDebug("FileSystem.copyTree - %s: '%s' -> '%s'" % (e, source, target))
return False
@pyqtSlot(str, result=bool) @pyqtSlot(str, result=bool)
def _removeDirectory(self, path): def _removeDirectory(self, path):
try: try:
@ -192,15 +201,6 @@ class FileSystem(QObject):
qDebug("FileSystem.removeTree - %s: '%s'" % (e, path)) qDebug("FileSystem.removeTree - %s: '%s'" % (e, path))
return False return False
@pyqtSlot(str, str, result=bool)
def copyTree(self, source, target):
try:
shutil.copytree(source, target)
return True
except IOError as (t, e):
qDebug("FileSystem.copyTree - %s: '%s' -> '%s'" % (e, source, target))
return False
@pyqtSlot(str, str, result=bool) @pyqtSlot(str, str, result=bool)
def copyLinkTree(self, source, target): def copyLinkTree(self, source, target):
try: try:

View File

@ -85,7 +85,7 @@ class Phantom(QObject):
self.m_page.mainFrame().addToJavaScriptWindowObject('fs', self.m_filesystem) self.m_page.mainFrame().addToJavaScriptWindowObject('fs', self.m_filesystem)
jsShims = ( jsShims = (
':/fs-shim.js', ':/filesystem-shim.js',
':/webpage-shim.js' ':/webpage-shim.js'
) )
for shim in jsShims: for shim in jsShims:

View File

@ -1,7 +1,7 @@
<RCC> <RCC>
<qresource prefix="/"> <qresource prefix="/">
<file>configurator.js</file> <file>configurator.js</file>
<file>fs-shim.js</file> <file>filesystem-shim.js</file>
<file>webpage-shim.js</file> <file>webpage-shim.js</file>
<file>resources/coffee-script.js</file> <file>resources/coffee-script.js</file>
<file>resources/pyphantomjs-icon.png</file> <file>resources/pyphantomjs-icon.png</file>