Compare commits


2 Commits

Author SHA1 Message Date
  Matteo Cypriani bf7e090fbf Add option --fs-fix=<auto|force|no> 2 years ago
  Matteo Cypriani 20baa5ecd9 Strip trailing whitespaces 2 years ago
4 changed files with 44 additions and 31 deletions
Split View
  1. +3
  2. +1
  3. +36
  4. +4

+ 3
- 3

@ -1,7 +1,7 @@
gcp 0.1.3 (20/06/11):
- fixed exit status
- updated manpage with exit status
- gcp DIR1 DIR2 syntax fixed
- gcp DIR1 DIR2 syntax fixed
- tests
gcp 0.1.2 (16/06/11):
- removed bad fd close
@ -10,12 +10,12 @@ gcp 0.1.2 (16/06/11):
- unaccessible source dir crash fix
- os.stat precision fix
- manpage
- install script
- install script
gcp 0.1.1 (30/09/10):
- double entry check in journal
- unicode source_path send via dbus (second instance of gcp) fixed
- errors are now shown after copy
- fixed bad closure when a file already exists
- added "gcp SOURCE_FILE DEST_FILE" syntax management
- added "gcp SOURCE_FILE DEST_FILE" syntax management
gcp 0.1 (28/09/10):

+ 1
- 1
README View File

@ -35,7 +35,7 @@ gcp is a file copier, loosely inspired from cp, but with high level functionalit
gcp is at an early stage of development, and really experimental: use at your own risks !
** How to use it ? **
Pretty much like cp (see gcp --help).
Pretty much like cp (see gcp --help).
Please note that the behaviour is not exactly the same as cp, even if gcp want to be option-compatible. Mainly, the destination filenames can be changed (by default, can be deactivated).
gcp doesn't implement yet all the options from cp, but it's planed.

+ 36
- 23
gcp View File

@ -69,10 +69,11 @@ This software is an advanced file copier
Get the latest version at
const_DBUS_INTERFACE = "org.goffi.gcp"
const_DBUS_INTERFACE = "org.goffi.gcp"
const_DBUS_PATH = "/org/goffi/gcp"
const_BUFF_SIZE = 4096
const_PRESERVE = set(['mode','ownership','timestamps'])
const_FS_FIX = set(['auto','force','no'])
const_FILES_DIR = "~/.gcp"
const_JOURNAL_PATH = const_FILES_DIR + "/journal"
const_SAVED_LIST = const_FILES_DIR + "/saved_list"
@ -86,7 +87,7 @@ class DbusObject(dbus.service.Object):
dbus.service.Object.__init__(self, bus, path)
debug(_("Init DbusObject..."))
in_signature='', out_signature='s')
def getVersion(self):
@ -294,7 +295,7 @@ class GCP():
dest_path = os.path.normpath(os.path.join(source_dir, args.pop()))
except OSError,e:
error (_("Invalid dest_path: %s"),e)
for path in args:
abspath = os.path.normpath(os.path.join(os.path.expanduser(source_dir), path))
if not os.path.exists(abspath):
@ -312,7 +313,7 @@ class GCP():
def __copyNextFile(self):
"""Take the last file in the list, and launch the copy using glib io_watch event
@return: True a file was added, False else"""
@return: True a file was added, False else"""
if self.copy_list:
source_file, dest_path, options = self.copy_list.pop()
@ -341,7 +342,7 @@ class GCP():
return True
(dest_fd, options), priority=gobject.PRIORITY_DEFAULT)
if not self.progress:
@ -362,7 +363,7 @@ class GCP():
def _copyFile(self, source_fd, condition, data):
@ -411,7 +412,7 @@ class GCP():
@return: fixed filename"""
fixed_filename = filename
if self.getFsType(filename) == 'vfat' and options.fs_fix:
if options.fs_fix == 'force' or (options.fs_fix == 'auto' and self.getFsType(filename) == 'vfat'):
fixed_filename = filename.replace('\\','_')\
@ -520,7 +521,7 @@ class GCP():
if options.sources_save or options.sources_replace:
if saved_files.has_key(options.sources_save) and not options.sources_replace:
error(_("There is already a saved sources with this name, skipping --sources-save"))
error(_("There is already a saved sources with this name, skipping --sources-save"))
if len(args)>1:
saved_files[options.sources_save] = map(os.path.abspath,args[:-1])
@ -552,38 +553,41 @@ class GCP():
if isinstance(full_args[idx], unicode):
#We don't want unicode as some filenames can be invalid unicode
full_args[idx] = full_args[idx].encode('utf-8')
parser = OptionParser(usage=_usage,version=ABOUT)
parser.add_option("-r", "--recursive", action="store_true", default=False,
help=_("copy directories recursively"))
parser.add_option("-f", "--force", action="store_true", default=False,
help=_("force overwriting of existing files"))
parser.add_option("--preserve", action="store", default='mode,ownership,timestamps',
help=_("preserve the specified attributes"))
parser.add_option("-L", "--dereference", action="store_true", default=False,
help=_("always follow symbolic links in sources"))
parser.add_option("-P", "--no-dereference", action="store_false", dest='dereference',
help=_("never follow symbolic links in sources"))
#parser.add_option("--no-unicode-fix", action="store_false", dest='unicode_fix', default=True,
# help=_("don't fix name encoding errors")) #TODO
parser.add_option("--no-fs-fix", action="store_false", dest='fs_fix', default=True,
help=_("don't fix filesystem name incompatibily"))
parser.add_option("--fs-fix", action="store", dest='fs_fix', default='auto',
help=_("fix filesystem name incompatibily; can be 'auto' (default), 'force' or 'no'"))
parser.add_option("--no-fs-fix", action="store_true", dest='no_fs_fix', default=False,
help=_("same as --fs-fix=no (overrides --fs-fix)"))
parser.add_option("--no-progress", action="store_false", dest="progress", default=True,
help=_("deactivate progress bar"))
parser.add_option("-v", "--verbose", action="store_true", default=False,
help=_("Show what is currently done"))
group_saving = OptionGroup(parser, "sources saving")
group_saving.add_option("--sources-save", action="store",
help=_("Save source arguments"))
@ -592,19 +596,19 @@ class GCP():
group_saving.add_option("--sources-load", action="store",
help=_("Load source arguments"))
group_saving.add_option("--sources-del", action="store",
help=_("delete saved sources"))
group_saving.add_option("--sources-list", action="store_true", default=False,
help=_("List names of saved sources"))
group_saving.add_option("--sources-full-list", action="store_true", default=False,
help=_("List names of saved sources and files in it"))
(options, args) = parser.parse_args(full_args)
options.directdir = False #True only in the special case: we are copying a dir and it doesn't exists
#options check
@ -617,9 +621,18 @@ class GCP():
if options.verbose:
if options.no_fs_fix:
options.fs_fix = 'no'
if not options.fs_fix in const_FS_FIX:
error (_("Invalid --fs-fix value\nvalid values are:"))
for value in const_FS_FIX:
error('- %s' % value)
preserve = set(options.preserve.split(','))
if not preserve.issubset(const_PRESERVE):
error (_("Invalide --preserve value\nvalid values are:"))
error (_("Invalid --preserve value\nvalid values are:"))
for value in const_PRESERVE:
error('- %s' % value)
@ -642,7 +655,7 @@ class GCP():
options.dest_file = None
options.dest_file = None
#if there is an other instance of gcp, we send options to it
if not self._main_instance:
info (_("There is already one instance of %s running, pluging to it") % NAME_SHORT)

+ 4
- 4 View File

@ -59,8 +59,8 @@ def dirCheck(dir_path):
if isdir(full_path):
recursive_sum(full_path, result)
result[full_path] = sha1sum(full_path)
result[full_path] = sha1sum(full_path)
result = {}
_ori_dir = getcwd()
@ -94,7 +94,7 @@ def makeRandomFile(path, size=S10K, buf_size=4096):
def makeTestDir(path):
"""Helper method to easily create a test dir
@param path: where the dir must be created"""
for i in range(2):
subdir = join(path,'subdir_%d' % i)
@ -198,7 +198,7 @@ class TestCopyCases(unittest.TestCase):
check_2 = dirCheck('dest_dir')
self.assertEqual(check_1, check_2)
def test_mixt_copy_existing_dest_nonrecursive(self):
"""Check that a mixt copy (files + dir) to an existing dest without the recursive option work as expected"""
for i in range(2):