Compare commits

...

16 Commits

9 changed files with 667 additions and 441 deletions

View File

@ -1,21 +1,35 @@
gcp 0.1.3 (20/06/11):
- fixed exit status
- updated manpage with exit status
- gcp DIR1 DIR2 syntax fixed
- tests
gcp 0.1.2 (16/06/11):
- removed bad fd close
- crash fix when source file can't be openned
- symbolic link skipping (--dereferrence and --no-dereferrence options)
- unaccessible source dir crash fix
- os.stat precision fix
- manpage
- 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
gcp 0.1 (28/09/10):
**INITIAL PUBLIC RELEASE**
gcp 0.2.0 (UNRELEASED, Matteo Cypriani):
- actually switch to Python3
- cp compatibibility:
+ don't preserve any attributes by default (Jingbei Li)
+ added -p switch (same as --preserve=mode,ownership,timestamps)
+ added -R switch (same as --recursive)
- new --fs-fix option
gcp 0.1.4.dev1 (unreleased, Jingbei Li):
- main Python3 migration work
gcp 0.1.3 (2011-06-20, Goffi):
- fixed exit status
- updated manpage with exit status
- gcp DIR1 DIR2 syntax fixed
- tests
gcp 0.1.2 (2011-06-16, Goffi):
- removed bad fd close
- crash fix when source file can't be openned
- symbolic link skipping (--dereferrence and --no-dereferrence options)
- unaccessible source dir crash fix
- os.stat precision fix
- manpage
- install script
gcp 0.1.1 (2010-09-30, Goffi):
- 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
gcp 0.1 (2010-09-28, Goffi):
- **INITIAL PUBLIC RELEASE**

View File

@ -1,5 +1,5 @@
include MANIFEST.in distribute_setup.py gcp.1
include MANIFEST.in gcp.1
global-include *.py
global-include *.po *.mo
global-include CHANGELOG COPYING* INSTALL README*
global-include CHANGELOG COPYING* README*
global-exclude *.un~ *.swp

View File

@ -45,6 +45,27 @@ functionalities such as:
risks!
Installing
==========
The Python way
--------------
pip3 install gcp
Note that you should have the following packages installed so that pip can
complete the installation (Debian packages names, but you get the idea):
- libdbus-1-dev
- libdbus-glib-1-dev
- libgirepository1.0-dev
- libcairo2-dev
On Debian-based systems
-----------------------
apt install gcp
How to use it?
==============

267
fr.po
View File

@ -1,38 +1,36 @@
# Goffi's CoPier.
# Copyright (C) 2010 Jérôme Poisson
# gcp -- French translation file
# Copyright:
# 2010 Jérôme Poisson (Goffi) <goffi@goffi.org>
# 2018 Matteo Cypriani <mcy@lm7.fr>
# This file is distributed under the same license as the gcp package.
# Jérôme Poisson (Goffi) <goffi@goffi.org>, 2010.
# Goffi <goffi@goffi.org>, 2010.
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: 0.1\n"
"Project-Id-Version: 0.2.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-09-30 18:05+0800\n"
"PO-Revision-Date: 2010-09-30 18:09+0800\n"
"Last-Translator: Goffi <goffi@goffi.org>\n"
"Language-Team: French <goffi@goffi.org>\n"
"PO-Revision-Date: 2018-04-22 20:35+0200\n"
"Last-Translator: Matteo Cypriani <mcy@lm7.fr>\n"
"Language: French\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: gcp:43
#: gcp:45
msgid "Error during import"
msgstr "Erreur pendant l'import de bibliothèques"
#: gcp:44
#: gcp:46
msgid "Please check dependecies:"
msgstr "Merci de vérifier les dépendances"
msgstr "Merci de vérifier les dépendances :"
#: gcp:50
msgid ""
"ProgressBar not available, please download it at http://pypi.python.org/pypi/"
"progressbar"
#: gcp:52
msgid "ProgressBar not available, please download it at https://pypi.org/"
msgstr ""
"«ProgressBar» n'est pas disponible, merci de le télécharger à http://pypi."
"python.org/pypi/progressbar"
"ProgressBar n'est pas disponible, merci de le télécharger depuis"
"https://pypi.org/"
#: gcp:51
#: gcp:3
msgid ""
"Progress bar deactivated\n"
"--\n"
@ -40,235 +38,240 @@ msgstr ""
"Barre de progression désactivée\n"
"--\n"
#: gcp:62
msgid ""
"This program comes with ABSOLUTELY NO WARRANTY;\n"
"This is free software, and you are welcome to redistribute it\n"
"under certain conditions.\n"
"---\n"
"\n"
"This software is an advanced file copier\n"
"Get the latest version at http://www.goffi.org\n"
msgstr ""
"This program comes with ABSOLUTELY NO WARRANTY;\n"
"This is free software, and you are welcome to redistribute it\n"
"under certain conditions.\n"
"---\n"
"\n"
"Ce logiciel est un copieur de fichiers avancé\n"
"Vous pouvez télécharger la dernière version à http://www.goffi.org\n"
#: gcp:86
#: gcp:88
msgid "Init DbusObject..."
msgstr "Initialisation de «DbusObject»"
#: gcp:106
#: gcp:109
msgid "INTERNAL ERROR: invalid arguments"
msgstr "ERREUR INTERNE: arguments invalides"
msgstr "ERREUR INTERNE : arguments invalides"
#: gcp:110
msgid "INTERNAL ERROR: invalid source_path"
msgstr "ERREUR INTERNE:.chemin source invalide"
#: gcp:114
msgid "INTERNAL ERROR: invalid source_dir"
msgstr "ERREUR INTERNE : chemin source invalide"
#: gcp:165
#: gcp:169
msgid "/!\\ THE FOLLOWING FILES WERE *NOT* SUCCESSFULY COPIED:"
msgstr "/!\\ LES FICHIERS SUIVANTS *N'ONT PAS* ÉTÉ COPIÉS:"
msgstr "/!\\ LES FICHIERS SUIVANTS N'ONT *PAS* ÉTÉ COPIÉS :"
#: gcp:171
#: gcp:175
msgid "The following files were copied, but some errors happened:"
msgstr ""
"Les fichiers suivant ont été copiés, mais quelques erreurs sont survenues:"
"Les fichiers suivant ont été copiés, mais quelques erreurs sont survenues :"
#: gcp:177
#: gcp:181
#, python-format
msgid "Please check journal: %s"
msgstr "Merci de vérifier le journal: %s"
msgstr "Merci de vérifier le journal : %s"
#: gcp:199
#: gcp:203
msgid "gcp launched"
msgstr "gcp lancé"
#: gcp:207
#: gcp:211
msgid "Init DBus..."
msgstr "Initialisation de Dbus..."
#: gcp:237
#: gcp:241
msgid "Can't read mounts table"
msgstr "Impossible de lire la table des montages"
#: gcp:244
#: gcp:248
#, python-format
msgid "Adding to copy list: %(path)s ==> %(dest_path)s (%(fs_type)s)"
msgstr "Ajout à la liste des copies: %(path)s ==> %(dest_path)s (%(fs_type)s)"
msgstr "Ajout à la liste des copies : %(path)s ==> %(dest_path)s (%(fs_type)s)"
#: gcp:251
#: gcp:253
#, python-format
msgid "Can't copy %(path)s: %(exception)s"
msgstr "Impossible de copier %(path)s: %(exception)s"
msgstr "Impossible de copier %(path)s : %(exception)s"
#: gcp:274
#: gcp:280
#, python-format
msgid "Can't append %(path)s to copy list: %(exception)s"
msgstr ""
"Impossible d'ajouter %(path)s à la liste des fichiers à copier: %(exception)s"
"Impossible d'ajouter %(path)s à la liste des fichiers à copier : %(exception)s"
#: gcp:283
#, python-format
msgid "Invalid dest_path: %s"
msgstr "Chemin de destination invalide: %s"
msgid "Can't access %(dirpath)s: %(exception)s"
msgstr "Impossible d'accéder à %(dirpath)s : %(exception)s"
#: gcp:288
#: gcp:295
#, python-format
msgid "Invalid dest_path: %s"
msgstr "Chemin de destination invalide : %s"
#: gcp:300
#, python-format
msgid "The path given in arg doesn't exist or is not accessible: %s"
msgstr "Le chemin donné en argument n'existe pas ou n'est pas accessible: %s"
msgstr "Le chemin donné en argument n'existe pas ou n'est pas accessible : %s"
#: gcp:293
#: gcp:304
#, python-format
msgid "omitting directory \"%s\""
msgstr "Répertoire \"%s\" ignoré"
#: gcp:310
#: gcp:329
#, python-format
msgid "File [%s] already exists, skipping it !"
msgid "File [%s] already exists, skipping it!"
msgstr "Le fichier [%s] existe déjà, je le saute !"
#: gcp:328
#: gcp:347
#, python-format
msgid "COPYING %(source)s ==> %(dest)s"
msgstr "COPIE %(source)s ==> %(dest)s"
#: gcp:429
#: gcp:447
#, python-format
msgid "%.2f PiB"
msgstr "%.2f Pio"
#: gcp:431
#: gcp:449
#, python-format
msgid "%.2f TiB"
msgstr "%.2f Tio"
#: gcp:433
#: gcp:451
#, python-format
msgid "%.2f GiB"
msgstr "%.2f Gio"
#: gcp:435
#: gcp:453
#, python-format
msgid "%.2f MiB"
msgstr "%.2f Mio"
#: gcp:437
#: gcp:455
#, python-format
msgid "%.2f KiB"
msgstr "%.2f Kio"
#: gcp:439
#: gcp:457
#, python-format
msgid "%i B"
msgstr "%i o"
#: gcp:447 gcp:452
#: gcp:465 gcp:470
#, python-format
msgid "Copying %s"
msgstr "Copie de %s"
#: gcp:479 gcp:512
#: gcp:497 gcp:530
msgid ""
"No saved sources with this name, check existing names with --sources-list"
msgstr ""
"Aucun sauvegarde de fichiers sources avec ce nom, veuillez vérifier les "
"lists existantes avec --sources-list"
"Aucune sauvegarde de fichiers sources avec ce nom, veuillez vérifier les "
"listes existantes avec --sources-list"
#: gcp:489
#: gcp:507
msgid "Saved sources:"
msgstr "Liste de sources sauvées:"
msgstr "Liste de sources sauvées :"
#: gcp:503
#: gcp:521
msgid ""
"There is already a saved sources with this name, skipping --sources-save"
msgstr "Il y a déjà une liste de sources avec ce nom, --sources-save ignoré"
#: gcp:539
msgid "copy directories recursively"
msgstr "copie les répertoire récursivement"
#: gcp:542
msgid "force overwriting of existing files"
msgstr "force le remplacement des fichiers déjà existants"
#: gcp:545
msgid "preserve the specified attributes"
msgstr "garde les attributs spécifiés"
#: gcp:551
msgid "don't fix filesystem name incompatibily"
msgstr ""
"Ne corrige pas les incompatibilités des noms pour le système de fichiers"
#: gcp:554
msgid "deactivate progress bar"
msgstr "désactive la barre de progression"
#: gcp:557
msgid "Show what is currently done"
msgstr "Affiche les opérations effectuées"
msgid "copy directories recursively"
msgstr "copier les répertoire récursivement"
#: gcp:562
msgid "Save source arguments"
msgstr "Sauvegarde la liste des fichiers sources"
#: gcp:561
msgid "force overwriting of existing files"
msgstr "forcer le remplacement des fichiers déjà existants"
#: gcp:565
msgid "Save source arguments and replace memory if it already exists"
#, python-format
msgid "same as --preserve=%s"
msgstr "raccourci pour --preserve=%s"
#: gcp:569
#, python-format
msgid ""
"preserve specified attributes; accepted values: 'all', or one or more "
"amongst %s"
msgstr ""
"Sauvegarde la liste des fichiers sources et la remplace si elle existe déjà"
#: gcp:568
msgid "Load source arguments"
msgstr "Réutilise les fichiers sources à copier"
#: gcp:571
msgid "delete saved sources"
msgstr "Supprime la liste des fichiers sources"
"préserver les attributs spécifiés; valeurs acceptées : "
"'all' ou un ou plusieurs éléments parmi %s"
#: gcp:574
msgid "List names of saved sources"
msgstr "Liste les noms des listes de fichiers sources"
msgid "always follow symbolic links in sources"
msgstr ""
#: gcp:577
#: gcp:578
msgid "never follow symbolic links in sources"
msgstr ""
#: gcp:586
msgid "fix filesystem name incompatibily (default: auto)"
msgstr ""
#: gcp:590
msgid "same as --fs-fix=no (overrides --fs-fix)"
msgstr "raccourci pour --fs-fix=no (--fs-fix sera ignoré)"
#: gcp:594
msgid "disable progress bar"
msgstr "désactiver la barre de progression"
#: gcp:598
msgid "Show what is currently done"
msgstr "afficher les opérations effectuées"
#: gcp:607
msgid "Save source arguments"
msgstr "sauvegarder la liste des fichiers source"
#: gcp:611
msgid "Save source arguments and replace memory if it already exists"
msgstr ""
"sauvegarder la liste des fichiers source et la remplacer si elle existe déjà"
#: gcp:615
msgid "Load source arguments"
msgstr "réutiliser les fichiers source à copier"
#: gcp:619
msgid "delete saved sources"
msgstr "supprimer la liste des fichiers source"
#: gcp:623
msgid "List names of saved sources"
msgstr "afficher les noms des listes de fichiers source"
#: gcp:627
msgid "List names of saved sources and files in it"
msgstr ""
"Liste les noms des listes de fichiers sources, en incluant les fichiers "
"afficher les noms des listes de fichiers sources, en incluant les fichiers "
"qu'elles contiennent"
#: gcp:585
#: gcp:639
msgid "Progress bar is not available, deactivating"
msgstr "La barre de progression n'est pas disponible, désactivation"
#: gcp:595
msgid ""
"Invalid --preserve value\n"
"valid values are:"
msgstr ""
"La valeur de «--preserve» est invalide\n"
"Les valeurs valides sont:"
#: gcp:663
#, python-format
msgid "Invalid --preserve value '%s'"
msgstr "Valeur de --preserve invalide « %s »"
#: gcp:616
#: gcp:690
#, python-format
msgid "There is already one instance of %s running, pluging to it"
msgstr "Il y a déjà une instance de %s lancée, je m'y connecte"
#: gcp:622
#: gcp:696
msgid "Wrong number of arguments"
msgstr "Nombre d'arguments invalide"
#: gcp:624
#: gcp:698
#, python-format
msgid "adding args to gcp: %s"
msgstr "ajout des arguments à gcp: %s"
msgstr "ajout des arguments à gcp : %s"
#: gcp:633
#: gcp:707
msgid "User interruption: good bye"
msgstr "Interruption par l'utilisateur: au revoir"
msgstr "Interruption par l'utilisateur : au revoir"
#~ msgid "don't fixe name encoding errors"
#~ msgstr "Ne corrige pas les erreurs dans l'encodage des noms"

356
gcp
View File

@ -2,8 +2,10 @@
"""
gcp: Goffi's CoPier
Copyright (C) 2010, 2011 Jérôme Poisson <goffi@goffi.org>
Copyright (c) 2010, 2011 Jérôme Poisson <goffi@goffi.org>
(c) 2011 Thomas Preud'homme <robotux@celest.fr>
(c) 2016 Jingbei Li <i@jingbei.li>
(c) 2018 Matteo Cypriani <mcy@lm7.fr>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -19,59 +21,60 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
### logging ###
import logging
from logging import debug, info, error, warning
logging.basicConfig(level=logging.INFO,
format='%(message)s')
###
import gettext
gettext.install('gcp', "i18n")
import sys
import os,os.path
from argparse import ArgumentParser
import os
import os.path
from argparse import ArgumentParser, RawDescriptionHelpFormatter
import pickle
logging.basicConfig(level=logging.INFO, format='%(message)s')
gettext.install('gcp', "i18n")
try:
from gi.repository import GObject
#DBus
import dbus, dbus.glib
import dbus
import dbus.glib
import dbus.service
import dbus.mainloop.glib
except ImportError as e:
error(_("Error during import"))
error(_("Please check dependecies:"),e)
error(_("Please check dependecies:"), e)
exit(1)
try:
from progressbar import ProgressBar, Percentage, Bar, ETA, FileTransferSpeed
pbar_available=True
except ImportError as e:
info (_('ProgressBar not available, please download it at http://pypi.python.org/pypi/progressbar'))
info (_("ProgressBar not available, please download it at https://pypi.org/"))
info (_('Progress bar deactivated\n--\n'))
pbar_available=False
NAME = "gcp (Goffi's copier)"
NAME_SHORT = "gcp"
VERSION = '0.1.3'
ABOUT = NAME+u" v"+VERSION+u""" (c) Jérôme Poisson (aka Goffi) 2010, 2011
VERSION = '0.2.0'
ABOUT = NAME_SHORT + " " + VERSION + """
---
"""+NAME+u""" Copyright (C) 2010 Jérôme Poisson
""" + _(u"""This program comes with ABSOLUTELY NO WARRANTY;
This is free software, and you are welcome to redistribute it
under certain conditions.
---
This software is an advanced file copier
Get the latest version at http://wiki.goffi.org/wiki/Gcp
""")
""" + NAME + """
Copyright: 2010-2011 Jérôme Poisson <goffi@goffi.org>
2011 Thomas Preud'homme <robotux@celest.fr>
2016 Jingbei Li <i@jingbei.li>
2018 Matteo Cypriani <mcy@lm7.fr>
This program comes with ABSOLUTELY NO WARRANTY; it is free software,
and you are welcome to redistribute it under certain conditions.
"""
const_DBUS_INTERFACE = "org.goffi.gcp"
const_DBUS_PATH = "/org/goffi/gcp"
const_BUFF_SIZE = 4096
const_PRESERVE = set(['mode','ownership','timestamps'])
const_PRESERVE_p = 'mode,ownership,timestamps'
const_FS_FIX = set(['auto','force','no'])
const_FILES_DIR = "~/.gcp"
const_JOURNAL_PATH = const_FILES_DIR + "/journal"
@ -228,14 +231,15 @@ class GCP():
def __getMountPoints(self):
"""Parse /proc/mounts to get currently mounted devices"""
#TODO: reparse when a new device is added/a device is removed
#(check freedesktop mounting signals)
# TODO: reparse when a new device is added/a device is removed
# (check freedesktop mounting signals)
ret = {}
try:
with open("/proc/mounts",'r') as mounts:
for line in mounts.readlines():
fs_spec, fs_file, fs_vfstype, fs_mntops, fs_freq, fs_passno = line.split(' ')
ret[fs_file] = fs_vfstype
fs_spec, fs_file, fs_vfstype, \
fs_mntops, fs_freq, fs_passno = line.split(' ')
ret[fs_file] = fs_vfstype
except:
error (_("Can't read mounts table"))
return ret
@ -244,12 +248,15 @@ class GCP():
"""Add a file to the copy list
@param path: absolute path of file
@param options: options as return by optparse"""
debug (_("Adding to copy list: %(path)s ==> %(dest_path)s (%(fs_type)s)") % {"path":path, "dest_path":dest_path, "fs_type":self.getFsType(dest_path)} )
debug(_("Adding to copy list: %(path)s ==> %(dest_path)s (%(fs_type)s)")
% {"path":path, "dest_path":dest_path,
"fs_type":self.getFsType(dest_path)})
try:
self.bytes_total+=os.path.getsize(path)
self.copy_list.insert(0,(path, dest_path, options))
except OSError as e:
error(_("Can't copy %(path)s: %(exception)s") % {'path':path, 'exception':e.strerror})
error(_("Can't copy %(path)s: %(exception)s")
% {'path':path, 'exception':e.strerror})
def __appendDirToList(self, dirpath, dest_path, options):
@ -309,49 +316,56 @@ class GCP():
self.__appendToList(abspath, dest_path, options)
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"""
if self.copy_list:
source_file, dest_path, options = self.copy_list.pop()
self.journal.startFile(source_file)
try:
source_fd = open(source_file, 'rb')
except:
self.journal.copyFailed()
self.journal.error("can't open source")
self.journal.closeFile()
return True
filename = os.path.basename(source_file)
assert(filename)
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:
warning (_("File [%s] already exists, skipping it !") % dest_file)
self.journal.copyFailed()
self.journal.error("already exists")
self.journal.closeFile()
source_fd.close()
return True
try:
dest_fd = open(dest_file, 'wb')
except:
self.journal.copyFailed()
self.journal.error("can't open dest")
self.journal.closeFile()
source_fd.close()
return True
GObject.io_add_watch(source_fd, GObject.IO_IN,self._copyFile,
(dest_fd, options), priority=GObject.PRIORITY_DEFAULT)
if not self.progress:
info(_("COPYING %(source)s ==> %(dest)s") % {"source":source_file, "dest":dest_file})
return True
else:
#Nothing left to copy, we quit
"""Takes the last file in the list and launches the copy using glib
io_watch event."""
if not self.copy_list:
# Nothing left to copy, we quit
if self.progress:
self.__pbar_finish()
self.journal.showErrors()
self.loop.quit()
source_file, dest_path, options = self.copy_list.pop()
self.journal.startFile(source_file)
try:
source_fd = open(source_file, 'rb')
except:
self.journal.copyFailed()
self.journal.error("can't open source")
self.journal.closeFile()
return
filename = os.path.basename(source_file)
assert(filename)
if options.dest_file:
dest_file = self.__filename_fix(options.dest_file, options)
else:
dest_file = self.__filename_fix(os.path.join(dest_path, filename),
options)
if os.path.exists(dest_file) and not options.force:
warning (_("File [%s] already exists, skipping it!") % dest_file)
self.journal.copyFailed()
self.journal.error("already exists")
self.journal.closeFile()
source_fd.close()
return
try:
dest_fd = open(dest_file, 'wb')
except:
self.journal.copyFailed()
self.journal.error("can't open dest")
self.journal.closeFile()
source_fd.close()
return
GObject.io_add_watch(source_fd, GObject.IO_IN,self._copyFile,
(dest_fd, options),
priority=GObject.PRIORITY_DEFAULT)
if not self.progress:
info(_("COPYING %(source)s ==> %(dest)s")
% {"source":source_file, "dest":dest_file})
def __copyFailed(self, reason, source_fd, dest_fd):
"""Write the failure in the journal and close files descriptors"""
self.journal.copyFailed()
@ -441,19 +455,17 @@ class GCP():
def __get_string_size(self, size):
"""Return a nice string representation of a size"""
if size>=2**50:
return _("%.2f PiB") % (float(size)/2**50)
elif size>=2**40:
return _("%.2f TiB") % (float(size)/2**40)
elif size>=2**30:
return _("%.2f GiB") % (float(size)/2**30)
elif size>=2**20:
return _("%.2f MiB") % (float(size)/2**20)
elif size>=2**10:
return _("%.2f KiB") % (float(size)/2**10)
else:
return _("%i B") % size
if size >= 2**50:
return _("%.2f PiB") % (float(size) / 2**50)
if size >= 2**40:
return _("%.2f TiB") % (float(size) / 2**40)
if size >= 2**30:
return _("%.2f GiB") % (float(size) / 2**30)
if size >= 2**20:
return _("%.2f MiB") % (float(size) / 2**20)
if size >= 2**10:
return _("%.2f KiB") % (float(size) / 2**10)
return _("%i B") % size
def _pbar_update(self):
"""Update progress bar position, create the bar if it doesn't exist"""
@ -461,12 +473,16 @@ class GCP():
try:
if self.pbar.maxval != self.bytes_total:
self.pbar.maxval = self.bytes_total
self.pbar.widgets[0] = _("Copying %s") % self.__get_string_size(self.bytes_total)
pbar_msg = _("Copying %s") % self.__get_string_size(self.bytes_total)
self.pbar.widgets[0] = pbar_msg
except AttributeError:
if not self.bytes_total:
#No progress bar if the files have a null size
# No progress bar if the files have a null size
return
self.pbar = ProgressBar(self.bytes_total,[_("Copying %s") % self.__get_string_size(self.bytes_total)," ",Percentage()," ",Bar()," ",FileTransferSpeed()," ",ETA()])
pbar_msg = _("Copying %s") % self.__get_string_size(self.bytes_total)
self.pbar = ProgressBar(self.bytes_total,
[pbar_msg, " ", Percentage(), " ", Bar(),
" ", FileTransferSpeed(), " ", ETA()])
self.pbar.start()
self.pbar.update(self.bytes_copied)
@ -492,7 +508,7 @@ class GCP():
saved_files={}
if options.sources_del:
if not saved_files.has_key(options.sources_del):
if options.sources_del not in saved_files:
error(_("No saved sources with this name, check existing names with --sources-list"))
else:
del saved_files[options.sources_del]
@ -504,7 +520,7 @@ class GCP():
if options.sources_list or options.sources_full_list:
info(_('Saved sources:'))
sources = saved_files.keys()
sources = list(saved_files.keys())
sources.sort()
for source in sources:
info("\t[%s]" % source)
@ -516,16 +532,16 @@ class GCP():
exit(0)
if options.sources_save or options.sources_replace:
if saved_files.has_key(options.sources_save) and not options.sources_replace:
if options.sources_save in saved_files and not options.sources_replace:
error(_("There is already a saved sources with this name, skipping --sources-save"))
else:
if len(args)>1:
saved_files[options.sources_save] = map(os.path.abspath,args[:-1])
saved_files[options.sources_save] = list(map(os.path.abspath,args[:-1]))
with open(os.path.expanduser(const_SAVED_LIST),'w') as saved_fd:
pickle.dump(saved_files,saved_fd)
if options.sources_load:
if not saved_files.has_key(options.sources_load):
if options.sources_load not in saved_files:
error(_("No saved sources with this name, check existing names with --sources-list"))
else:
saved_args = saved_files[options.sources_load]
@ -548,66 +564,92 @@ class GCP():
for idx in range(len(full_args)):
full_args[idx] = full_args[idx].encode('utf-8')
parser = ArgumentParser(usage=_usage)
parser = ArgumentParser(usage=_usage,
formatter_class=RawDescriptionHelpFormatter)
parser.add_argument("-r", "--recursive", action="store_true", default=False,
help=_("copy directories recursively"))
parser.add_argument("-f", "--force", action="store_true", default=False,
help=_("force overwriting of existing files"))
parser.add_argument("--preserve", action="store", default='',
help=_("preserve the specified attributes"))
parser.add_argument("-L", "--dereference", action="store_true", default=False,
help=_("always follow symbolic links in sources"))
parser.add_argument("-P", "--no-dereference", action="store_false", dest='dereference',
help=_("never follow symbolic links in sources"))
#parser.add_argument("--no-unicode-fix", action="store_false", dest='unicode_fix', default=True,
# help=_("don't fix name encoding errors")) #TODO
parser.add_argument("--fs-fix", choices = const_FS_FIX, dest='fs_fix', default='auto',
help=_("fix filesystem name incompatibily (default: auto)"))
parser.add_argument("--no-fs-fix", action="store_true", dest='no_fs_fix', default=False,
help=_("same as --fs-fix=no (overrides --fs-fix)"))
parser.add_argument("--no-progress", action="store_false", dest="progress", default=True,
help=_("deactivate progress bar"))
parser.add_argument("-v", "--verbose", action="store_true", default=False,
help=_("Show what is currently done"))
parser.add_argument("-V", "--version", action="version", version=ABOUT)
parser.add_argument("-r", "-R", "--recursive",
action="store_true", default=False,
help=_("copy directories recursively")
)
parser.add_argument("-f", "--force",
action="store_true", default=False,
help=_("force overwriting of existing files")
)
parser.add_argument("-p",
action="store_true", default=False,
help=_("same as --preserve=%s" % const_PRESERVE_p)
)
parser.add_argument("--preserve",
action="store", default='',
help=_("preserve specified attributes; accepted values: \
'all', or one or more amongst %s") % str(const_PRESERVE)
)
parser.add_argument("-L", "--dereference",
action="store_true", default=False,
help=_("always follow symbolic links in sources")
)
parser.add_argument("-P", "--no-dereference",
action="store_false", dest='dereference',
help=_("never follow symbolic links in sources")
)
#parser.add_argument("--no-unicode-fix",
# action="store_false", dest='unicode_fix', default=True,
# help=_("don't fix name encoding errors") #TODO
#)
parser.add_argument("--fs-fix",
choices = const_FS_FIX, dest='fs_fix', default='auto',
help=_("fix filesystem name incompatibily (default: auto)")
)
parser.add_argument("--no-fs-fix",
action="store_true", dest='no_fs_fix', default=False,
help=_("same as --fs-fix=no (overrides --fs-fix)")
)
parser.add_argument("--no-progress",
action="store_false", dest="progress", default=True,
help=_("disable progress bar")
)
parser.add_argument("-v", "--verbose",
action="store_true", default=False,
help=_("Show what is currently done")
)
parser.add_argument("-V", "--version",
action="version", version=ABOUT
)
group_saving = parser.add_argument_group("sources saving")
group_saving.add_argument("--sources-save", action="store",
help=_("Save source arguments"))
group_saving.add_argument("--sources-replace", action="store",
help=_("Save source arguments and replace memory if it already exists"))
group_saving.add_argument("--sources-load", action="store",
help=_("Load source arguments"))
group_saving.add_argument("--sources-del", action="store",
help=_("delete saved sources"))
group_saving.add_argument("--sources-list", action="store_true", default=False,
help=_("List names of saved sources"))
group_saving.add_argument("--sources-full-list", action="store_true", default=False,
help=_("List names of saved sources and files in it"))
group_saving.add_argument("--sources-save",
action="store",
help=_("Save source arguments")
)
group_saving.add_argument("--sources-replace",
action="store",
help=_("Save source arguments and replace memory if it already exists")
)
group_saving.add_argument("--sources-load",
action="store",
help=_("Load source arguments")
)
group_saving.add_argument("--sources-del",
action="store",
help=_("delete saved sources")
)
group_saving.add_argument("--sources-list",
action="store_true", default=False,
help=_("List names of saved sources")
)
group_saving.add_argument("--sources-full-list",
action="store_true", default=False,
help=_("List names of saved sources and files in it")
)
parser.add_argument_group(group_saving)
(options, args) = parser.parse_known_args()
options.directdir = False #True only in the special case: we are copying a dir and it doesn't exists
#options check
# True only in the special case: we are copying a dir and it doesn't
# exists:
options.directdir = False
# options check
if options.progress and not pbar_available:
warning (_("Progress bar is not available, deactivating"))
options.progress = self.progress = False
@ -620,18 +662,26 @@ class GCP():
if options.no_fs_fix:
options.fs_fix = 'no'
if len(options.preserve):
preserve = set(options.preserve.split(','))
if not preserve.issubset(const_PRESERVE):
error (_("Invalid --preserve value\nvalid values are:"))
for value in const_PRESERVE:
error('- %s' % value)
exit(1)
else:
options.preserve = preserve
preserve = set()
else:
options.preserve=set()
if options.p:
preserve.update(const_PRESERVE_p.split(','))
if options.preserve:
preserve.update(options.preserve.split(','))
preserve_all = False
for value in preserve:
if value == 'all':
preserve_all = True
continue
if value not in const_PRESERVE:
error (_("Invalid --preserve value '%s'") % value)
exit(1)
if preserve_all:
preserve.remove('all')
preserve.update(const_PRESERVE)
options.preserve = preserve
self.__sourcesSaving(options, args)

9
gcp.1
View File

@ -57,7 +57,7 @@ Show version of program and exit.
.B \-h, \-\-help
Show summary of options.
.TP
.B \-r, \-\-recursive
.B \-r, \-R, \-\-recursive
Copy directories recursively.
.TP
.B \-L, \-\-dereference
@ -69,10 +69,13 @@ never follow symbolic links in sources
.B \-f, \-\-force
Overwrite existing files.
.TP
.B \-p
Same as \-\-preserve=mode,ownership,timestamps
.TP
.B \-\-preserve=PRESERVE
Keep specified attributes. Attributes can be mode, ownership and timestamps.
When several attributes are passed, they need to be separated by commas. Note
that timestamps preservation has some limits, see section LIMITS.
that timestamps preservation has some limits, see section LIMITATIONS.
.TP
.B \-\-no\-fs\-fix
Don't fix file system naming incompatibilities.
@ -110,7 +113,7 @@ The exit status can be:
\fB1\fP if at least one file has not been copied, or if something went wrong.
.IP \[bu]
\fB2\fP if all files have been copied but with some issues
.SH LIMITS
.SH LIMITATIONS
Timestamps preservation with \-\-preserve option is limited by the os python
module on POSIX systems. Currently, python only returns timestamps in float
format, which is a smaller precision than what POSIX provides. Progress on this

210
gcp.po
View File

@ -6,159 +6,257 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Project-Id-Version: 0.2.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-09-27 13:03+0800\n"
"POT-Creation-Date: 2018-04-22 20:09+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: English\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: gcp:43
#: gcp:45
msgid "Error during import"
msgstr ""
#: gcp:44
#: gcp:46
msgid "Please check dependecies:"
msgstr ""
#: gcp:50
msgid ""
"ProgressBar not available, please download it at http://pypi.python.org/pypi/"
"progressbar"
#: gcp:52
msgid "ProgressBar not available, please download it at https://pypi.org/"
msgstr ""
#: gcp:51
#: gcp:3
msgid ""
"Progress bar deactivated\n"
"--\n"
msgstr ""
#: gcp:62
msgid ""
"This program comes with ABSOLUTELY NO WARRANTY;\n"
"This is free software, and you are welcome to redistribute it\n"
"under certain conditions.\n"
"---\n"
"\n"
"This software is an advanced file copier\n"
"Get the latest version at http://www.goffi.org\n"
msgstr ""
#: gcp:82
#: gcp:88
msgid "Init DbusObject..."
msgstr ""
#: gcp:102
#: gcp:109
msgid "INTERNAL ERROR: invalid arguments"
msgstr ""
#: gcp:119
#: gcp:114
msgid "INTERNAL ERROR: invalid source_dir"
msgstr ""
#: gcp:169
msgid "/!\\ THE FOLLOWING FILES WERE *NOT* SUCCESSFULY COPIED:"
msgstr ""
#: gcp:175
msgid "The following files were copied, but some errors happened:"
msgstr ""
#: gcp:181
#, python-format
msgid "Please check journal: %s"
msgstr ""
#: gcp:203
msgid "gcp launched"
msgstr ""
#: gcp:126
#: gcp:211
msgid "Init DBus..."
msgstr ""
#: gcp:155
#: gcp:241
msgid "Can't read mounts table"
msgstr ""
#: gcp:162
#: gcp:248
#, python-format
msgid "Adding to copy list: %(path)s ==> %(dest_path)s (%(fs_type)s)"
msgstr ""
#: gcp:170 gcp:192
#: gcp:253
#, python-format
msgid "Can't copy %(path)s: %(exception)s"
msgstr ""
#: gcp:179
#: gcp:280
#, python-format
msgid "Creating directory %s"
msgid "Can't append %(path)s to copy list: %(exception)s"
msgstr ""
#: gcp:200
#: gcp:283
#, python-format
msgid "Can't access %(dirpath)s: %(exception)s"
msgstr ""
#: gcp:295
#, python-format
msgid "Invalid dest_path: %s"
msgstr ""
#: gcp:205
#: gcp:300
#, python-format
msgid "The path given in arg doesn't exist or is not accessible: %s"
msgstr ""
#: gcp:210
#: gcp:304
#, python-format
msgid "omitting directory \"%s\""
msgstr ""
#: gcp:226
#: gcp:329
#, python-format
msgid "File [%s] already exists, skipping it !"
msgid "File [%s] already exists, skipping it!"
msgstr ""
#: gcp:233
#: gcp:347
#, python-format
msgid "COPYING %(source)s ==> %(dest)s"
msgstr ""
#: gcp:284
msgid "Progress: "
#: gcp:447
#, python-format
msgid "%.2f PiB"
msgstr ""
#: gcp:315
#: gcp:449
#, python-format
msgid "%.2f TiB"
msgstr ""
#: gcp:451
#, python-format
msgid "%.2f GiB"
msgstr ""
#: gcp:453
#, python-format
msgid "%.2f MiB"
msgstr ""
#: gcp:455
#, python-format
msgid "%.2f KiB"
msgstr ""
#: gcp:457
#, python-format
msgid "%i B"
msgstr ""
#: gcp:465 gcp:470
#, python-format
msgid "Copying %s"
msgstr ""
#: gcp:497 gcp:530
msgid ""
"No saved sources with this name, check existing names with --sources-list"
msgstr ""
#: gcp:507
msgid "Saved sources:"
msgstr ""
#: gcp:521
msgid ""
"There is already a saved sources with this name, skipping --sources-save"
msgstr ""
#: gcp:557
msgid "copy directories recursively"
msgstr ""
#: gcp:318
#: gcp:561
msgid "force overwriting of existing files"
msgstr ""
#: gcp:321
msgid "preserve the specified attributes"
#: gcp:565
#, python-format
msgid "same as --preserve=%s"
msgstr ""
#: gcp:324
msgid "don't fixe name encoding errors"
#: gcp:569
#, python-format
msgid ""
"preserve specified attributes; accepted values: 'all', or one or more "
"amongst %s"
msgstr ""
#: gcp:327
msgid "deactivate progress bar"
#: gcp:574
msgid "always follow symbolic links in sources"
msgstr ""
#: gcp:330
#: gcp:578
msgid "never follow symbolic links in sources"
msgstr ""
#: gcp:586
msgid "fix filesystem name incompatibily (default: auto)"
msgstr ""
#: gcp:590
msgid "same as --fs-fix=no (overrides --fs-fix)"
msgstr ""
#: gcp:594
msgid "disable progress bar"
msgstr ""
#: gcp:598
msgid "Show what is currently done"
msgstr ""
#: gcp:335
#: gcp:607
msgid "Save source arguments"
msgstr ""
#: gcp:611
msgid "Save source arguments and replace memory if it already exists"
msgstr ""
#: gcp:615
msgid "Load source arguments"
msgstr ""
#: gcp:619
msgid "delete saved sources"
msgstr ""
#: gcp:623
msgid "List names of saved sources"
msgstr ""
#: gcp:627
msgid "List names of saved sources and files in it"
msgstr ""
#: gcp:639
msgid "Progress bar is not available, deactivating"
msgstr ""
#: gcp:345
msgid ""
"Invalid --preserve value\n"
"valid values are:"
#: gcp:663
#, python-format
msgid "Invalid --preserve value '%s'"
msgstr ""
#: gcp:354
#: gcp:690
#, python-format
msgid "There is already one instance of %s running, pluging to it"
msgstr ""
#: gcp:360
#: gcp:696
msgid "Wrong number of arguments"
msgstr ""
#: gcp:362
#: gcp:698
#, python-format
msgid "adding args to gcp: %s"
msgstr ""
#: gcp:373
#: gcp:707
msgid "User interruption: good bye"
msgstr ""

View File

@ -1,28 +1,47 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
from setuptools import setup
import sys
from os import path
name = 'gcp'
setup(name=name,
version='0.1.4',
description=u"gcp is an advanced copy tool loosely inspired from cp",
long_description=u'gcp is a command-line tool to copy files, loosely inspired from cp, but with high level functionalities such as progress bar, copy continuation on error, journaling to know which files were successfuly copied, name mangling to workaround filesystem limitations (FAT), unique copy queue, copy list managemet, command arguments close to cp',
author='Goffi (Jérôme Poisson)',
author_email='goffi@goffi.org',
url='http://wiki.goffi.org/wiki/Gcp',
classifiers=['Environment :: Console',
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Topic :: Utilities'
],
data_files=[('share/locale/fr/LC_MESSAGES', ['i18n/fr/LC_MESSAGES/gcp.mo']),
('share/man/man1', ["gcp.1"]),
('share/doc/%s' % name, ['COPYING','README.md'])],
scripts=['gcp'],
)
setup(
name=name,
version='0.2.0',
url='https://code.lm7.fr/mcy/gcp',
license='GPL-3+',
description="An advanced file copy tool loosely inspired from cp",
long_description_content_type='text/markdown',
long_description="""
**%s** is a command-line tool to copy files, loosely inspired from the `cp`
command, but with higher-level functionalities such as progress bar, copy
continuation on error, logging to know which files were successfully
copied, name mangling to workaround filesystem limitations (FAT), unique
copy queue, copy list management, etc.""" % name,
keywords='file copy',
author='Goffi (Jérôme Poisson)',
author_email='goffi@goffi.org',
maintainer='Matteo Cypriani',
maintainer_email='mcy@lm7.fr',
# Cf. https://pypi.org/pypi?%3Aaction=list_classifiers
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3',
'Topic :: Utilities',
],
data_files=[
('share/locale/fr/LC_MESSAGES', ['i18n/fr/LC_MESSAGES/gcp.mo']),
('share/man/man1', ["gcp.1"]),
('share/doc/%s' % name, ['COPYING', 'README.md']),
],
scripts=['gcp'],
install_requires=['PyGObject', 'dbus-python'],
python_requires='>=3',
)

View File

@ -1,9 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
"""
gcp: Goffi's CoPier
Copyright (C) 2010, 2011 Jérôme Poisson <goffi@goffi.org>
gcp: Goffi's CoPier -- unit tests
Copyright (c) 2010, 2011 Jérôme Poisson <goffi@goffi.org>
Copyright (c) 2018 Matteo Cypriani <mcy@lm7.fr>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -19,29 +19,32 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from __future__ import with_statement
import tempfile
import unittest
from os import getcwd, chdir, system, mkdir, makedirs, listdir
from os.path import join, isdir
from shutil import rmtree
from random import randrange
from hashlib import sha1
#size shorcuts
# gcp command. This assumes gcp is in the PATH. Alternatively, we could use
# something like this to use gcp from the current directory:
#GCP = join(getcwd(), "gcp")
GCP = 'gcp'
# Size shorcuts
S10K = 1024 * 10
S100K = 1024 * 100
S1M = 1024 * 1024
S10M = 1024 * 1024 * 10
S100M = 1024 * 1024 * 100
def sha1sum(filename, buf_size=4096):
"""Return the SHA1 hash of a file
"""Returns the SHA1 hash of a file.
@param filename: path to the file
@param buf_size: size of the buffer to use for calculation"""
@param buf_size: size of the buffer to use for calculation
"""
csum = sha1()
with open(filename) as fd:
with open(filename, 'rb') as fd:
data = fd.read(buf_size)
while data:
csum.update(data)
@ -49,7 +52,7 @@ def sha1sum(filename, buf_size=4096):
return csum.digest()
def dirCheck(dir_path):
"""Recursively calculate SHA1 sum of a dir
"""Recursively calculates SHA1 sums in a directory.
@param path: path of the dir to check
@return: a dict in the form [{filepath: sum,...}]
"""
@ -69,11 +72,12 @@ def dirCheck(dir_path):
return result
#def makeRandomFile(path, size, buf_size=4096):
# """Create a fake file
# """Creates a fake file.
# @param path: where the file is created
# @param size: size of the file to create in bytes"""
# @param size: size of the file to create in bytes
# """
# def seq(size):
# return ''.join(chr(randrange(256)) for i in range(size))
# return ''.join(chr(random.randrange(256)) for i in range(size))
# fd = open(path, 'w')
# for byte in range(size//buf_size):
# fd.write(seq(buf_size))
@ -81,20 +85,22 @@ def dirCheck(dir_path):
# fd.close()
def makeRandomFile(path, size=S10K, buf_size=4096):
"""Create a fake file using /dev/urandom
"""Creates a fake file using /dev/urandom.
@param path: where the file must be created
@param size: size of the file to create in bytes"""
source = open('/dev/urandom','r')
dest = open(path, 'w')
for byte in range(size//buf_size):
@param size: size of the file to create in bytes
"""
source = open('/dev/urandom', 'rb')
dest = open(path, 'wb')
for _ in range(size // buf_size):
dest.write(source.read(buf_size))
dest.write(source.read(size%buf_size))
dest.write(source.read(size % buf_size))
dest.close()
source.close()
def makeTestDir(path):
"""Helper method to easily create a test dir
@param path: where the dir must be created"""
"""Helper method to easily create a test directory.
@param path: where the dir must be created
"""
for i in range(2):
subdir = join(path,'subdir_%d' % i)
makedirs(subdir)
@ -104,8 +110,8 @@ def makeTestDir(path):
makeRandomFile(join(path,'file_%d' % i), S10K)
class TestCopyCases(unittest.TestCase):
"""Test basic copy use cases, using gcp externally
gcp must be available in the PATH"""
"""Test basic copy use cases, using gcp externally.
"""
#TODO: check journal
def setUp(self):
@ -118,109 +124,121 @@ class TestCopyCases(unittest.TestCase):
rmtree(self.tmp_dir)
def test_one_file_copy(self):
"""Copy one file and test the result"""
"""Copies one file and tests the result.
"""
makeRandomFile('file_1', S10K)
ori_sum = sha1sum('file_1')
ret = system("gcp file_1 file_2")
ret = system(GCP + " file_1 file_2")
self.assertEqual(ret,0)
dest_sum = sha1sum('file_2')
self.assertEqual(ori_sum, dest_sum)
def test_one_file_copy_already_exists(self):
"""Check that an existing file is not overwritten"""
"""Checks that an existing file is not overwritten.
"""
makeRandomFile('file_1', S10K)
makeRandomFile('file_2', S10K)
file_2_sum = sha1sum('file_2')
ret = system("gcp file_1 file_2")
ret = system(GCP + " file_1 file_2")
self.assertNotEqual(ret,0)
file_2_sum_bis = sha1sum('file_2')
self.assertEqual(file_2_sum, file_2_sum_bis)
def test_one_file_copy_already_exists_force(self):
"""Check that an existing file is overwritten with --force"""
"""Checks that an existing file is overwritten with --force.
"""
makeRandomFile('file_1', S10K)
makeRandomFile('file_2', S10K)
file_1_sum = sha1sum('file_1')
ret = system("gcp -f file_1 file_2")
ret = system(GCP + " -f file_1 file_2")
self.assertEqual(ret,0)
file_2_sum_bis = sha1sum('file_2')
self.assertEqual(file_1_sum, file_2_sum_bis)
def test_one_dir_copy(self):
"""Check copy of one dir to a non existant path"""
"""Checks copy of a directory to a non-existent path.
"""
makeTestDir('dir_1')
check_1 = dirCheck('dir_1')
ret = system("gcp -r dir_1 dir_2")
ret = system(GCP + " -r dir_1 dir_2")
self.assertEqual(ret,0)
check_2 = dirCheck('dir_2')
self.assertEqual(check_1, check_2)
def test_one_dir_copy_nocopy(self):
"""Check that a dir is not copied without the recursive option"""
"""Checks that a directory is not copied without the recursive option.
"""
makeTestDir('dir_1')
check_before = dirCheck('.')
ret = system("gcp dir_1 dir_2")
ret = system(GCP + " dir_1 dir_2")
self.assertEqual(ret,0)
check_after = dirCheck('.')
self.assertEqual(check_before, check_after)
def test_one_dir_copy_existing_dest(self):
"""Check that a dir is copied inside an existing destination"""
"""Checks that a directory is copied inside an existing destination.
"""
makeTestDir('dir_1')
mkdir('dir_2')
check_1 = dirCheck('dir_1')
ret = system("gcp -r dir_1 dir_2")
ret = system(GCP + " -r dir_1 dir_2")
self.assertEqual(ret,0)
self.assertEqual(listdir('dir_2'), ['dir_1'])
check_2 = dirCheck('dir_2/dir_1')
self.assertEqual(check_1, check_2)
def test_mixt_copy_existing_dest(self):
"""Check that a mixt copy (files + dir) to an existing dest work as expected"""
def test_mixed_copy_existing_dest(self):
"""Mixed copy (files + dir) to an existing destination.
"""
for i in range(2):
makeRandomFile('file_%d' % i, S10K)
makeTestDir('dir_%d' % i)
check_1 = dirCheck('.')
mkdir('dest_dir')
ret = system("gcp -r file_0 file_1 dir_0 dir_1 dest_dir")
ret = system(GCP + " -r file_0 file_1 dir_0 dir_1 dest_dir")
self.assertEqual(ret,0)
check_2 = dirCheck('dest_dir')
self.assertEqual(check_1, check_2)
def test_mixt_copy_nonexisting_dest(self):
"""Check that a mixt copy (files + dir) to an non existing dest work as expected
/!\\ the behavious is different of the one of cp in this case ! (cp doesn't copy at all, while gcp create the dest)"""
def test_mixed_copy_nonexisting_dest(self):
"""Mixed copy (files + dir) to an inexistant destination.
/!\\ The behaviour is different than cp's! (cp doesn't copy at all,
while gcp create the destintation directory.)
"""
for i in range(2):
makeRandomFile('file_%d' % i, S10K)
makeTestDir('dir_%d' % i)
check_1 = dirCheck('.')
ret = system("gcp -r file_0 file_1 dir_0 dir_1 dest_dir")
ret = system(GCP + " -r file_0 file_1 dir_0 dir_1 dest_dir")
self.assertEqual(ret,0)
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"""
def test_mixed_copy_existing_dest_nonrecursive(self):
"""Non-recursive mixed copy (files + dir) to an existing destination.
"""
for i in range(2):
makeRandomFile('file_%d' % i, S10K)
makeTestDir('dir_%d' % i)
mkdir('dest_dir')
ret = system("gcp file_0 file_1 dir_0 dir_1 dest_dir")
ret = system(GCP + " file_0 file_1 dir_0 dir_1 dest_dir")
self.assertEqual(ret,0)
self.assertEqual(set(listdir('dest_dir')), set(['file_0', 'file_1']))
self.assertEqual(sha1sum('file_0'), sha1sum('dest_dir/file_0'))
self.assertEqual(sha1sum('file_1'), sha1sum('dest_dir/file_1'))
def test_mixt_copy_nonexisting_dest_nonrecursive(self):
"""Check that a mixt copy (files + dir) to an existing dest without the recursive option work as expected"""
def test_mixed_copy_nonexisting_dest_nonrecursive(self):
"""Non-recursive mixed copy (files + dir) to an inexistant destination.
"""
for i in range(2):
makeRandomFile('file_%d' % i, S10K)
makeTestDir('dir_%d' % i)
check_before = dirCheck('.')
ret = system("gcp file_0 file_1 dir_0 dir_1 dest_dir")
ret = system(GCP + " file_0 file_1 dir_0 dir_1 dest_dir")
self.assertEqual(ret >> 8, 1)
check_after = dirCheck('.')
self.assertEqual(check_before, check_after)
if __name__ == '__main__':
unittest.main()