mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add -f option to cp
This commit is contained in:
parent
2350a75c22
commit
30afc7b865
@ -58,6 +58,9 @@ class ArgumentError(ProtocolError):
|
|||||||
|
|
||||||
class PathError(ArgumentError):
|
class PathError(ArgumentError):
|
||||||
""" When a user supplies an incorrect/invalid path """
|
""" When a user supplies an incorrect/invalid path """
|
||||||
|
def __init__(self, msg, path=None):
|
||||||
|
ArgumentError.__init__(self, msg)
|
||||||
|
self.path = path
|
||||||
|
|
||||||
class ControlError(ProtocolError):
|
class ControlError(ProtocolError):
|
||||||
""" Errors in Command/Response pairs while communicating with the device """
|
""" Errors in Command/Response pairs while communicating with the device """
|
||||||
|
@ -22,6 +22,7 @@ import StringIO, sys, time, os
|
|||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
from libprs500 import __version__ as VERSION
|
from libprs500 import __version__ as VERSION
|
||||||
|
from libprs500.devices.errors import PathError
|
||||||
from libprs500.devices.prs500.driver import PRS500
|
from libprs500.devices.prs500.driver import PRS500
|
||||||
from libprs500.devices.prs500.cli.terminfo import TerminalController
|
from libprs500.devices.prs500.cli.terminfo import TerminalController
|
||||||
from libprs500.devices.errors import ArgumentError, DeviceError, DeviceLocked
|
from libprs500.devices.errors import ArgumentError, DeviceError, DeviceLocked
|
||||||
@ -252,6 +253,8 @@ def main():
|
|||||||
"source must point to a file for which you have read permissions\n"+\
|
"source must point to a file for which you have read permissions\n"+\
|
||||||
"destination must point to a file or directory for which you have write permissions"
|
"destination must point to a file or directory for which you have write permissions"
|
||||||
parser = OptionParser(usage=usage)
|
parser = OptionParser(usage=usage)
|
||||||
|
parser.add_option('-f', '--force', dest='force', action='store_true', default=False,
|
||||||
|
help='Overwrite the destination file if it exists already.')
|
||||||
options, args = parser.parse_args(args)
|
options, args = parser.parse_args(args)
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
@ -277,7 +280,14 @@ def main():
|
|||||||
print >> sys.stderr, e
|
print >> sys.stderr, e
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
return 1
|
return 1
|
||||||
dev.put_file(infile, args[1][7:])
|
try:
|
||||||
|
dev.put_file(infile, args[1][7:])
|
||||||
|
except PathError, err:
|
||||||
|
if options.force and 'exists' in str(err):
|
||||||
|
dev.del_file(err.path, False)
|
||||||
|
dev.put_file(infile, args[1][7:])
|
||||||
|
else:
|
||||||
|
raise
|
||||||
infile.close()
|
infile.close()
|
||||||
else:
|
else:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
@ -679,7 +679,7 @@ class PRS500(Device):
|
|||||||
else:
|
else:
|
||||||
if not replace_file:
|
if not replace_file:
|
||||||
raise PathError("Cannot write to " + \
|
raise PathError("Cannot write to " + \
|
||||||
path + " as it already exists")
|
path + " as it already exists", path=path)
|
||||||
_file = self.path_properties(path, end_session=False)
|
_file = self.path_properties(path, end_session=False)
|
||||||
if _file.file_size > bytes:
|
if _file.file_size > bytes:
|
||||||
self.del_file(path, end_session=False)
|
self.del_file(path, end_session=False)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user