Compare commits

..

No commits in common. "b2dcbd83687ff15436718384799813d340b5c90f" and "4c02959204d9065a44c945318b1ade46aa163e64" have entirely different histories.

9 changed files with 435 additions and 661 deletions

View File

@ -1,35 +1,21 @@
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**
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**

View File

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

View File

@ -45,27 +45,6 @@ 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?
==============

253
fr.po
View File

@ -1,36 +1,38 @@
# gcp -- French translation file
# Copyright:
# 2010 Jérôme Poisson (Goffi) <goffi@goffi.org>
# 2018 Matteo Cypriani <mcy@lm7.fr>
# Goffi's CoPier.
# Copyright (C) 2010 Jérôme Poisson
# 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.2.0\n"
"Project-Id-Version: 0.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-09-30 18:05+0800\n"
"PO-Revision-Date: 2018-04-22 20:35+0200\n"
"Last-Translator: Matteo Cypriani <mcy@lm7.fr>\n"
"Language: French\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"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: gcp:45
#: gcp:43
msgid "Error during import"
msgstr "Erreur pendant l'import de bibliothèques"
#: gcp:46
#: gcp:44
msgid "Please check dependecies:"
msgstr "Merci de vérifier les dépendances :"
msgstr "Merci de vérifier les dépendances"
#: gcp:52
msgid "ProgressBar not available, please download it at https://pypi.org/"
#: gcp:50
msgid ""
"ProgressBar not available, please download it at http://pypi.python.org/pypi/"
"progressbar"
msgstr ""
"ProgressBar n'est pas disponible, merci de le télécharger depuis"
"https://pypi.org/"
"«ProgressBar» n'est pas disponible, merci de le télécharger à http://pypi."
"python.org/pypi/progressbar"
#: gcp:3
#: gcp:51
msgid ""
"Progress bar deactivated\n"
"--\n"
@ -38,240 +40,235 @@ msgstr ""
"Barre de progression désactivée\n"
"--\n"
#: gcp:88
#: 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
msgid "Init DbusObject..."
msgstr "Initialisation de «DbusObject»"
#: gcp:109
#: gcp:106
msgid "INTERNAL ERROR: invalid arguments"
msgstr "ERREUR INTERNE : arguments invalides"
msgstr "ERREUR INTERNE: arguments invalides"
#: gcp:114
msgid "INTERNAL ERROR: invalid source_dir"
msgstr "ERREUR INTERNE : chemin source invalide"
#: gcp:110
msgid "INTERNAL ERROR: invalid source_path"
msgstr "ERREUR INTERNE:.chemin source invalide"
#: gcp:169
#: gcp:165
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:175
#: gcp:171
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:181
#: gcp:177
#, python-format
msgid "Please check journal: %s"
msgstr "Merci de vérifier le journal : %s"
msgstr "Merci de vérifier le journal: %s"
#: gcp:203
#: gcp:199
msgid "gcp launched"
msgstr "gcp lancé"
#: gcp:211
#: gcp:207
msgid "Init DBus..."
msgstr "Initialisation de Dbus..."
#: gcp:241
#: gcp:237
msgid "Can't read mounts table"
msgstr "Impossible de lire la table des montages"
#: gcp:248
#: gcp:244
#, 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:253
#: gcp:251
#, 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:280
#: gcp:274
#, 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 "Can't access %(dirpath)s: %(exception)s"
msgstr "Impossible d'accéder à %(dirpath)s : %(exception)s"
#: gcp:295
#, python-format
msgid "Invalid dest_path: %s"
msgstr "Chemin de destination invalide : %s"
msgstr "Chemin de destination invalide: %s"
#: gcp:300
#: gcp:288
#, 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:304
#: gcp:293
#, python-format
msgid "omitting directory \"%s\""
msgstr "Répertoire \"%s\" ignoré"
#: gcp:329
#: gcp:310
#, 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:347
#: gcp:328
#, python-format
msgid "COPYING %(source)s ==> %(dest)s"
msgstr "COPIE %(source)s ==> %(dest)s"
#: gcp:447
#: gcp:429
#, python-format
msgid "%.2f PiB"
msgstr "%.2f Pio"
#: gcp:449
#: gcp:431
#, python-format
msgid "%.2f TiB"
msgstr "%.2f Tio"
#: gcp:451
#: gcp:433
#, python-format
msgid "%.2f GiB"
msgstr "%.2f Gio"
#: gcp:453
#: gcp:435
#, python-format
msgid "%.2f MiB"
msgstr "%.2f Mio"
#: gcp:455
#: gcp:437
#, python-format
msgid "%.2f KiB"
msgstr "%.2f Kio"
#: gcp:457
#: gcp:439
#, python-format
msgid "%i B"
msgstr "%i o"
#: gcp:465 gcp:470
#: gcp:447 gcp:452
#, python-format
msgid "Copying %s"
msgstr "Copie de %s"
#: gcp:497 gcp:530
#: gcp:479 gcp:512
msgid ""
"No saved sources with this name, check existing names with --sources-list"
msgstr ""
"Aucune sauvegarde de fichiers sources avec ce nom, veuillez vérifier les "
"listes existantes avec --sources-list"
"Aucun sauvegarde de fichiers sources avec ce nom, veuillez vérifier les "
"lists existantes avec --sources-list"
#: gcp:507
#: gcp:489
msgid "Saved sources:"
msgstr "Liste de sources sauvées :"
msgstr "Liste de sources sauvées:"
#: gcp:521
#: gcp:503
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:557
#: gcp:539
msgid "copy directories recursively"
msgstr "copier les répertoire récursivement"
msgstr "copie les répertoire récursivement"
#: gcp:561
#: gcp:542
msgid "force overwriting of existing files"
msgstr "forcer le remplacement des fichiers déjà existants"
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"
#: gcp:562
msgid "Save source arguments"
msgstr "Sauvegarde la liste des fichiers sources"
#: gcp:565
#, 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 ""
"préserver les attributs spécifiés; valeurs acceptées : "
"'all' ou un ou plusieurs éléments parmi %s"
#: gcp:574
msgid "always follow symbolic links in sources"
msgstr ""
#: 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à"
"Sauvegarde la liste des fichiers sources et la remplace si elle existe déjà"
#: gcp:615
#: gcp:568
msgid "Load source arguments"
msgstr "réutiliser les fichiers source à copier"
msgstr "Réutilise les fichiers sources à copier"
#: gcp:619
#: gcp:571
msgid "delete saved sources"
msgstr "supprimer la liste des fichiers source"
msgstr "Supprime la liste des fichiers sources"
#: gcp:623
#: gcp:574
msgid "List names of saved sources"
msgstr "afficher les noms des listes de fichiers source"
msgstr "Liste les noms des listes de fichiers sources"
#: gcp:627
#: gcp:577
msgid "List names of saved sources and files in it"
msgstr ""
"afficher les noms des listes de fichiers sources, en incluant les fichiers "
"Liste les noms des listes de fichiers sources, en incluant les fichiers "
"qu'elles contiennent"
#: gcp:639
#: gcp:585
msgid "Progress bar is not available, deactivating"
msgstr "La barre de progression n'est pas disponible, désactivation"
#: gcp:663
#, python-format
msgid "Invalid --preserve value '%s'"
msgstr "Valeur de --preserve invalide « %s »"
#: gcp:595
msgid ""
"Invalid --preserve value\n"
"valid values are:"
msgstr ""
"La valeur de «--preserve» est invalide\n"
"Les valeurs valides sont:"
#: gcp:690
#: gcp:616
#, 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:696
#: gcp:622
msgid "Wrong number of arguments"
msgstr "Nombre d'arguments invalide"
#: gcp:698
#: gcp:624
#, python-format
msgid "adding args to gcp: %s"
msgstr "ajout des arguments à gcp : %s"
msgstr "ajout des arguments à gcp: %s"
#: gcp:707
#: gcp:633
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"

358
gcp
View File

@ -2,10 +2,8 @@
"""
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
@ -21,60 +19,59 @@ 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
import sys
import os
import os.path
from argparse import ArgumentParser, RawDescriptionHelpFormatter
import pickle
logging.basicConfig(level=logging.INFO, format='%(message)s')
gettext.install('gcp', "i18n")
import sys
import os,os.path
from argparse import ArgumentParser
import pickle
try:
from gi.repository import GObject
#DBus
import dbus
import dbus.glib
import dbus, 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 https://pypi.org/"))
info (_('ProgressBar not available, please download it at http://pypi.python.org/pypi/progressbar'))
info (_('Progress bar deactivated\n--\n'))
pbar_available=False
NAME = "gcp (Goffi's copier)"
NAME_SHORT = "gcp"
VERSION = '0.2.0'
VERSION = '0.1.3'
ABOUT = NAME+u" v"+VERSION+u""" (c) Jérôme Poisson (aka Goffi) 2010, 2011
ABOUT = NAME_SHORT + " " + VERSION + """
---
""" + 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.
"""
"""+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
""")
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"
@ -231,15 +228,14 @@ 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
@ -248,15 +244,12 @@ 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):
@ -316,56 +309,49 @@ class GCP():
self.__appendToList(abspath, dest_path, options)
def __copyNextFile(self):
"""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
"""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
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()
@ -455,17 +441,19 @@ 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)
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
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
def _pbar_update(self):
"""Update progress bar position, create the bar if it doesn't exist"""
@ -473,16 +461,12 @@ class GCP():
try:
if self.pbar.maxval != self.bytes_total:
self.pbar.maxval = self.bytes_total
pbar_msg = _("Copying %s") % self.__get_string_size(self.bytes_total)
self.pbar.widgets[0] = pbar_msg
self.pbar.widgets[0] = _("Copying %s") % self.__get_string_size(self.bytes_total)
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
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 = ProgressBar(self.bytes_total,[_("Copying %s") % self.__get_string_size(self.bytes_total)," ",Percentage()," ",Bar()," ",FileTransferSpeed()," ",ETA()])
self.pbar.start()
self.pbar.update(self.bytes_copied)
@ -508,7 +492,7 @@ class GCP():
saved_files={}
if options.sources_del:
if options.sources_del not in saved_files:
if not saved_files.has_key(options.sources_del):
error(_("No saved sources with this name, check existing names with --sources-list"))
else:
del saved_files[options.sources_del]
@ -520,7 +504,7 @@ class GCP():
if options.sources_list or options.sources_full_list:
info(_('Saved sources:'))
sources = list(saved_files.keys())
sources = saved_files.keys()
sources.sort()
for source in sources:
info("\t[%s]" % source)
@ -532,16 +516,16 @@ class GCP():
exit(0)
if options.sources_save or options.sources_replace:
if options.sources_save in saved_files and not 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"))
else:
if len(args)>1:
saved_files[options.sources_save] = list(map(os.path.abspath,args[:-1]))
saved_files[options.sources_save] = 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 options.sources_load not in saved_files:
if not saved_files.has_key(options.sources_load):
error(_("No saved sources with this name, check existing names with --sources-list"))
else:
saved_args = saved_files[options.sources_load]
@ -564,92 +548,66 @@ class GCP():
for idx in range(len(full_args)):
full_args[idx] = full_args[idx].encode('utf-8')
parser = ArgumentParser(usage=_usage,
formatter_class=RawDescriptionHelpFormatter)
parser = ArgumentParser(usage=_usage)
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
)
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)
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()
# True only in the special case: we are copying a dir and it doesn't
# exists:
options.directdir = False
# options check
options.directdir = False #True only in the special case: we are copying a dir and it doesn't exists
#options check
if options.progress and not pbar_available:
warning (_("Progress bar is not available, deactivating"))
options.progress = self.progress = False
@ -662,26 +620,18 @@ class GCP():
if options.no_fs_fix:
options.fs_fix = 'no'
preserve = set()
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
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
else:
options.preserve=set()
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, \-R, \-\-recursive
.B \-r, \-\-recursive
Copy directories recursively.
.TP
.B \-L, \-\-dereference
@ -69,13 +69,10 @@ 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 LIMITATIONS.
that timestamps preservation has some limits, see section LIMITS.
.TP
.B \-\-no\-fs\-fix
Don't fix file system naming incompatibilities.
@ -113,7 +110,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 LIMITATIONS
.SH LIMITS
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,257 +6,159 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: 0.2.0\n"
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-04-22 20:09+0200\n"
"POT-Creation-Date: 2010-09-27 13:03+0800\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=UTF-8\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: gcp:45
#: gcp:43
msgid "Error during import"
msgstr ""
#: gcp:46
#: gcp:44
msgid "Please check dependecies:"
msgstr ""
#: gcp:52
msgid "ProgressBar not available, please download it at https://pypi.org/"
#: gcp:50
msgid ""
"ProgressBar not available, please download it at http://pypi.python.org/pypi/"
"progressbar"
msgstr ""
#: gcp:3
#: gcp:51
msgid ""
"Progress bar deactivated\n"
"--\n"
msgstr ""
#: gcp:88
#: 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
msgid "Init DbusObject..."
msgstr ""
#: gcp:109
#: gcp:102
msgid "INTERNAL ERROR: invalid arguments"
msgstr ""
#: 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
#: gcp:119
msgid "gcp launched"
msgstr ""
#: gcp:211
#: gcp:126
msgid "Init DBus..."
msgstr ""
#: gcp:241
#: gcp:155
msgid "Can't read mounts table"
msgstr ""
#: gcp:248
#: gcp:162
#, python-format
msgid "Adding to copy list: %(path)s ==> %(dest_path)s (%(fs_type)s)"
msgstr ""
#: gcp:253
#: gcp:170 gcp:192
#, python-format
msgid "Can't copy %(path)s: %(exception)s"
msgstr ""
#: gcp:280
#: gcp:179
#, python-format
msgid "Can't append %(path)s to copy list: %(exception)s"
msgid "Creating directory %s"
msgstr ""
#: gcp:283
#, python-format
msgid "Can't access %(dirpath)s: %(exception)s"
msgstr ""
#: gcp:295
#: gcp:200
#, python-format
msgid "Invalid dest_path: %s"
msgstr ""
#: gcp:300
#: gcp:205
#, python-format
msgid "The path given in arg doesn't exist or is not accessible: %s"
msgstr ""
#: gcp:304
#: gcp:210
#, python-format
msgid "omitting directory \"%s\""
msgstr ""
#: gcp:329
#: gcp:226
#, python-format
msgid "File [%s] already exists, skipping it!"
msgid "File [%s] already exists, skipping it !"
msgstr ""
#: gcp:347
#: gcp:233
#, python-format
msgid "COPYING %(source)s ==> %(dest)s"
msgstr ""
#: gcp:447
#, python-format
msgid "%.2f PiB"
#: gcp:284
msgid "Progress: "
msgstr ""
#: 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
#: gcp:315
msgid "copy directories recursively"
msgstr ""
#: gcp:561
#: gcp:318
msgid "force overwriting of existing files"
msgstr ""
#: gcp:565
#, python-format
msgid "same as --preserve=%s"
#: gcp:321
msgid "preserve the specified attributes"
msgstr ""
#: gcp:569
#, python-format
msgid ""
"preserve specified attributes; accepted values: 'all', or one or more "
"amongst %s"
#: gcp:324
msgid "don't fixe name encoding errors"
msgstr ""
#: gcp:574
msgid "always follow symbolic links in sources"
#: gcp:327
msgid "deactivate progress bar"
msgstr ""
#: 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
#: gcp:330
msgid "Show what is currently done"
msgstr ""
#: 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
#: gcp:335
msgid "Progress bar is not available, deactivating"
msgstr ""
#: gcp:663
#, python-format
msgid "Invalid --preserve value '%s'"
#: gcp:345
msgid ""
"Invalid --preserve value\n"
"valid values are:"
msgstr ""
#: gcp:690
#: gcp:354
#, python-format
msgid "There is already one instance of %s running, pluging to it"
msgstr ""
#: gcp:696
#: gcp:360
msgid "Wrong number of arguments"
msgstr ""
#: gcp:698
#: gcp:362
#, python-format
msgid "adding args to gcp: %s"
msgstr ""
#: gcp:707
#: gcp:373
msgid "User interruption: good bye"
msgstr ""

View File

@ -1,47 +1,28 @@
#!/usr/bin/env python3
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from setuptools import setup
import sys
from os import path
name = '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',
)
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'],
)

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python3
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
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>
gcp: Goffi's CoPier
Copyright (C) 2010, 2011 Jérôme Poisson <goffi@goffi.org>
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,32 +19,29 @@ 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
# 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
#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):
"""Returns the SHA1 hash of a file.
"""Return 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, 'rb') as fd:
with open(filename) as fd:
data = fd.read(buf_size)
while data:
csum.update(data)
@ -52,7 +49,7 @@ def sha1sum(filename, buf_size=4096):
return csum.digest()
def dirCheck(dir_path):
"""Recursively calculates SHA1 sums in a directory.
"""Recursively calculate SHA1 sum of a dir
@param path: path of the dir to check
@return: a dict in the form [{filepath: sum,...}]
"""
@ -72,12 +69,11 @@ def dirCheck(dir_path):
return result
#def makeRandomFile(path, size, buf_size=4096):
# """Creates a fake file.
# """Create 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(random.randrange(256)) for i in range(size))
# return ''.join(chr(randrange(256)) for i in range(size))
# fd = open(path, 'w')
# for byte in range(size//buf_size):
# fd.write(seq(buf_size))
@ -85,22 +81,20 @@ def dirCheck(dir_path):
# fd.close()
def makeRandomFile(path, size=S10K, buf_size=4096):
"""Creates a fake file using /dev/urandom.
"""Create 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', 'rb')
dest = open(path, 'wb')
for _ in range(size // buf_size):
@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):
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 directory.
@param path: where the dir must be created
"""
"""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)
makedirs(subdir)
@ -110,8 +104,8 @@ def makeTestDir(path):
makeRandomFile(join(path,'file_%d' % i), S10K)
class TestCopyCases(unittest.TestCase):
"""Test basic copy use cases, using gcp externally.
"""
"""Test basic copy use cases, using gcp externally
gcp must be available in the PATH"""
#TODO: check journal
def setUp(self):
@ -124,121 +118,109 @@ class TestCopyCases(unittest.TestCase):
rmtree(self.tmp_dir)
def test_one_file_copy(self):
"""Copies one file and tests the result.
"""
"""Copy one file and test 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):
"""Checks that an existing file is not overwritten.
"""
"""Check 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):
"""Checks that an existing file is overwritten with --force.
"""
"""Check 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):
"""Checks copy of a directory to a non-existent path.
"""
"""Check copy of one dir to a non existant 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):
"""Checks that a directory is not copied without the recursive option.
"""
"""Check that a dir 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):
"""Checks that a directory is copied inside an existing destination.
"""
"""Check that a dir 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_mixed_copy_existing_dest(self):
"""Mixed copy (files + dir) to an existing destination.
"""
def test_mixt_copy_existing_dest(self):
"""Check that a mixt copy (files + dir) to an existing dest work as expected"""
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_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.)
"""
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)"""
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_mixed_copy_existing_dest_nonrecursive(self):
"""Non-recursive mixed copy (files + dir) to an existing destination.
"""
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):
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_mixed_copy_nonexisting_dest_nonrecursive(self):
"""Non-recursive mixed copy (files + dir) to an inexistant destination.
"""
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"""
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()