Added 'gcp file dest_file' syntax management

This commit is contained in:
Goffi 2010-09-30 17:56:59 +08:00
parent 3df4c89e01
commit 7226074954
1 changed files with 13 additions and 2 deletions

15
gcp
View File

@ -305,7 +305,7 @@ class GCP():
source_fd = open(source_file, 'rb') source_fd = open(source_file, 'rb')
filename = os.path.basename(source_file) filename = os.path.basename(source_file)
assert(filename) assert(filename)
dest_file = self.__filename_fix(os.path.join(dest_path,filename),options) dest_file = self.__filename_fix(options.dest_file,options) if options.dest_file else self.__filename_fix(os.path.join(dest_path,filename),options)
if os.path.exists(dest_file) and not options.force: if os.path.exists(dest_file) and not options.force:
warning (_("File [%s] already exists, skipping it !") % dest_file.decode('utf-8','replace')) warning (_("File [%s] already exists, skipping it !") % dest_file.decode('utf-8','replace'))
self.journal.copyFailed() self.journal.copyFailed()
@ -523,7 +523,8 @@ class GCP():
@return: a tuple (boolean, message) where the boolean is the success of the arguments @return: a tuple (boolean, message) where the boolean is the success of the arguments
validation, and message is the error message to print when necessary""" validation, and message is the error message to print when necessary"""
_usage=""" _usage="""
%prog [options] FILE1 [FILE2 ...] DEST %prog [options] FILE DEST
%prog [options] FILE1 [FILE2 ...] DEST-DIR
%prog --help for options list %prog --help for options list
""" """
@ -599,6 +600,16 @@ class GCP():
options.preserve = preserve options.preserve = preserve
self.__sourcesSaving(options, args) self.__sourcesSaving(options, args)
if len(args) == 2:
dest_path = os.path.abspath(os.path.expanduser(args[1]))
if not os.path.exists(dest_path) or os.path.isfile(dest_path):
options.dest_file = dest_path
args[1] = os.path.dirname(dest_path)
else:
options.dest_file = None
else:
options.dest_file = None
#if there is an other instance of gcp, we send options to it #if there is an other instance of gcp, we send options to it
if not self._main_instance: if not self._main_instance: