Compare commits

..

2 Commits

Author SHA1 Message Date
Matteo Cypriani bf7e090fbf Add option --fs-fix=<auto|force|no>
Currently, the filesystem fixes are applied only for FAT, in which these
special characters (:, ", etc.) are actually forbidden. NTFS, however, will
allow you to create file names containing these characters, but Windows will
still be unable to deal with the files (even to rename them!).

--fs-fix=force will be useful when copying to a NTFS filesystem that will be
read on Windows.

--fs-fix=no is the same as --no-fs-fix.

--fs-fix=auto is the same as the current default behaviour (i.e. fix names only
for FAT).
2018-04-15 12:32:39 +02:00
Matteo Cypriani 20baa5ecd9 Strip trailing whitespaces 2018-04-15 11:49:29 +02:00
16 changed files with 1260 additions and 1115 deletions

5
.gitignore vendored
View File

@ -1,5 +0,0 @@
*.pyc
*.pyv
*.sw*
*.tar*
*.egg

6
.hgignore Normal file
View File

@ -0,0 +1,6 @@
syntax: glob
*.pyc
*.pyv
*.swp
*.swo
tags

View File

@ -1,41 +1,21 @@
gcp 0.2.1 (2019-03-10, Matteo Cypriani):
- fix deprecation warnings with dbus.glib
see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=923677
- minor documentation (README) improvements
gcp 0.2.0 (2018-10-14, 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 --fix-filenames option
- reworked packaging
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

5
MANIFEST.in Normal file
View File

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

102
README Normal file
View File

@ -0,0 +1,102 @@
gcp v0.1.3
(c) Jérôme Poisson aka Goffi 2010, 2011
gcp (Goffi's cp) is a files copier.
** LICENSE **
gcp is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
gcp is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with gcp. If not, see <http://www.gnu.org/licenses/>.
** WTF ? **
gcp is a file copier, loosely inspired from cp, but with high level functionalities like:
- progression indicator
- gcp continue copying even when there is an issue: he just skip the file with problem, and go on
- journalization: gcp write what he is doing, this allow to know which files were effectively copied
- fixing names to be compatible with the target filesystem (e.g. removing incompatible chars like "?" or "*" on vfat)
- if you launch a copy when an other is already running, the files are added to the first queue, this avoid your hard drive to move its read/write head all the time
- files saving: you can keep track of files you have copied, and re-copy them later (useful when, for example, you always copy some free music to all your friends).
- gcp will be approximately option-compatible with cp (approximately because the behaviour is not exactly the same, see below)
/!\ WARNING /!\
gcp is at an early stage of development, and really experimental: use at your own risks !
** How to use it ? **
Pretty much like cp (see gcp --help).
Please note that the behaviour is not exactly the same as cp, even if gcp want to be option-compatible. Mainly, the destination filenames can be changed (by default, can be deactivated).
gcp doesn't implement yet all the options from cp, but it's planed.
** journalizaion **
The journal is planed to be used by gcp itself, buts remains human-readable. It is located in ~/.gcp/journal
3 states are used:
- OK means the file is copied and all operation were successful
- PARTIAL means the file is copied, but something went wrong (e.g. changing the permissions of the file)
- FAILED: the file is *not* copied
after the state, a list of things which went wront are show, separated by ", "
** What's next ? **
Several improvment are already planed
- copy queue management (moving copy order)
- advanced console interface
- notification (xmpp and maybe mail) when a long copy is finished
- retry for files which were not correctly copied
- badly encoded unicode filenames fix
- file copy integrity check
... and other are with a "maybe"
- graphic interface
- desktop (Kde, Gnome, XFCE, ...) integration
- distant copy (ftp)
- basic server mode, for copying files on network without the need of nfs or other heavy stuff
** Credits **
A big big thank to the authors/contributors of...
progressbar:
gcp use ProgressBar (http://pypi.python.org/pypi/progressbar/2.2), a class coded by Nilton Volpato which allow the textual representation of progression.
GLib:
This heavily used library is used here for the main loop, event catching, and for DBus. Get it at http://library.gnome.org/devel/glib/
DBus:
This excellent IPC is in the heart of gcp. Get more information at www.freedesktop.org/wiki/Software/dbus
python and its amazing standard library:
gcp was coded quickly for my own need thanks to this excellent and efficient language and its really huge standard library. Python can be download at www.python.org
If I forgot any credit, please contact me (mail below) to fix it.
Big thanks to contributors and package mainteners
** Contributions **
2011: Thomas Preud'homme <robotux@celest.fr>: manpage, stat resolution fix
** Contact **
You can contact me at goffi@goffi.org .
You'll find the latest version on my ftp: ftp://ftp.goffi.org/gcp, or check the wiki ( http://wiki.goffi.org/wiki/Gcp )
Please report any bug on http://bugs.goffi.org
You can also have a look to my other main projects (and maybe to the smaller ones too ;) ):
- lm (list movie): a tool to list movies using IMdB data, loosely inspired from ls
- SàT: my main project, a jabber/XMPP client, which is a brick to many others things I have in mind
Don't hesitate to give feedback :)

167
README.md
View File

@ -1,167 +0,0 @@
gcp
===
gcp is a user-friendly file copier written in Python. Its name used to stand
for "Goffi's CoPier", but was changed into a recursive acronym: Gcp CoPier.
License
=======
gcp is free software: you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.
gcp is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a [copy of the GNU General Public License](LICENSE)
along with gcp. If not, see <http://www.gnu.org/licenses/>.
About
=====
gcp is a file copier, loosely inspired from cp, but with high level
functionalities such as:
- **Progress bar.**
- gcp **keeps copying** even when there is an issue: it just skips the file,
logs an error and goes on.
- **Logging**: gcp writes what it's doing to a log file; this allows you to
know which files were effectively copied.
- **Fixing file names** to be compatible with the target filesystem (e.g.
removing incompatible chars like `?` or `*` on FAT).
- **Queue**: if you launch a copy when another copy is already running, the
files are added to the first queue; this optimizes hard drive head movement
and filesystem fragmentation.
- **Files saving**: you can keep track of the files you have copied, and copy
them again later (useful when, for example, you copy some free music to your
friends on a regular basis).
- gcp will be **approximately option-compatible with (GNU) cp** (approximately
because the behaviour is not exactly the same, see below).
**WARNING**: gcp is at a relatively early stage of development, use at your own
risks!
Installing
==========
The Python way
--------------
First, install the following packages on your system (these Debian packages
names, they may be different on other distros/systems):
- libdbus-1-dev
- libdbus-glib-1-dev
- libgirepository1.0-dev
- libcairo2-dev
- python3-cairo-dev
Then install gcp with pip:
pip3 install gcp
On Debian-based systems
-----------------------
apt install gcp
How to use it?
==============
Pretty much like cp (see `gcp --help` and `man gcp`).
Please note that the behaviour is not exactly the same as cp's, even if gcp
aims to be option-compatible. Mainly, the destination filenames can be modified
(cf. the `--fix-filenames` option).
gcp doesn't implement all the options GNU cp has yet, but it's a long-term
goal.
Logging
=======
The log file is aimed to be used by gcp itself, buts remains human-readable. It
is located in `~/.gcp/journal`.
3 states are used:
- **OK** means the file was copied and all operation were successful.
- **PARTIAL** means the file was copied, but something went wrong (file
permissions could not be preserved, file name had to be changed, etc.).
- **FAILED**: the file was *not* copied.
After the state, a list of things that went wrong is shown, separated by ", ".
Contribution ideas
==================
Here are some ideas for future developments:
- handle XDG
- copy queue management (moving copy order)
- advanced console interface
- notification (XMPP and maybe email) when a long copy is finished
- retry for files that were not correctly copied
- badly encoded unicode filenames fix
- file copy integrity check
And in an even more distant future:
- graphic interface
- desktop (Kde, Gnome, XFCE...) integration
- distant copy (FTP)
- basic server mode, for copying files on network without the need of NFS or
other heavy stuff
Credits
=======
A big big thanks to the authors/contributors of...
* **progressbar**:
gcp uses [ProgressBar](https://pypi.python.org/pypi/progressbar), a class
coded by Nilton Volpato that allows the textual representation of
progression.
* **GLib**:
This heavily used library is used here for the main loop, event catching, and
for DBus. Get it at <https://developer.gnome.org/glib/>.
* **DBus**:
This excellent IPC is ut the heart of gcp. Get more information at
<https://www.freedesktop.org/wiki/Software/dbus/>.
* **Python** and its amazing standard library:
gcp was coded quickly for my own needs thanks to this excellent and efficient
language and its really huge standard library. Python can be download at
<https://www.python.org/>.
If I forgot any credit, please contact me (email below) to fix that.
Big thanks to contributors and package maintainers.
Contributors
============
* Original author: Jérôme Poisson a.k.a. Goffi <goffi@goffi.org> 2010-2011.
* Thomas Preud'homme <robotux@celest.fr> 2011: manpage, stat resolution fix.
* Jingbei Li a.k.a. petronny 2016: conversion to Python3.
* Matteo Cypriani <mcy@lm7.fr> 2018: `--fix-filenames` option, Python3 fixes.
Contact
=======
Feedback, bug reports, patches, etc. are welcome, either by email or on the
repository's issue tracker <https://code.lm7.fr/mcy/gcp/issues>.
You can also have a look at Goffi's other main project, [Salut à
Toi](https://www.salut-a-toi.org/) (SàT), a Jabber/XMPP-based multi-frontend,
multipurpose communication tool.
Don't hesitate to give feedback :)

485
distribute_setup.py Normal file
View File

@ -0,0 +1,485 @@
#!python
"""Bootstrap distribute installation
If you want to use setuptools in your package's setup.py, just include this
file in the same directory with it, and add this to the top of your setup.py::
from distribute_setup import use_setuptools
use_setuptools()
If you want to require a specific version of setuptools, set a download
mirror, or use an alternate download directory, you can do so by supplying
the appropriate options to ``use_setuptools()``.
This file can also be run as a script to install or upgrade setuptools.
"""
import os
import sys
import time
import fnmatch
import tempfile
import tarfile
from distutils import log
try:
from site import USER_SITE
except ImportError:
USER_SITE = None
try:
import subprocess
def _python_cmd(*args):
args = (sys.executable,) + args
return subprocess.call(args) == 0
except ImportError:
# will be used for python 2.3
def _python_cmd(*args):
args = (sys.executable,) + args
# quoting arguments if windows
if sys.platform == 'win32':
def quote(arg):
if ' ' in arg:
return '"%s"' % arg
return arg
args = [quote(arg) for arg in args]
return os.spawnl(os.P_WAIT, sys.executable, *args) == 0
DEFAULT_VERSION = "0.6.14"
DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/"
SETUPTOOLS_FAKED_VERSION = "0.6c11"
SETUPTOOLS_PKG_INFO = """\
Metadata-Version: 1.0
Name: setuptools
Version: %s
Summary: xxxx
Home-page: xxx
Author: xxx
Author-email: xxx
License: xxx
Description: xxx
""" % SETUPTOOLS_FAKED_VERSION
def _install(tarball):
# extracting the tarball
tmpdir = tempfile.mkdtemp()
log.warn('Extracting in %s', tmpdir)
old_wd = os.getcwd()
try:
os.chdir(tmpdir)
tar = tarfile.open(tarball)
_extractall(tar)
tar.close()
# going in the directory
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
os.chdir(subdir)
log.warn('Now working in %s', subdir)
# installing
log.warn('Installing Distribute')
if not _python_cmd('setup.py', 'install'):
log.warn('Something went wrong during the installation.')
log.warn('See the error message above.')
finally:
os.chdir(old_wd)
def _build_egg(egg, tarball, to_dir):
# extracting the tarball
tmpdir = tempfile.mkdtemp()
log.warn('Extracting in %s', tmpdir)
old_wd = os.getcwd()
try:
os.chdir(tmpdir)
tar = tarfile.open(tarball)
_extractall(tar)
tar.close()
# going in the directory
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
os.chdir(subdir)
log.warn('Now working in %s', subdir)
# building an egg
log.warn('Building a Distribute egg in %s', to_dir)
_python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)
finally:
os.chdir(old_wd)
# returning the result
log.warn(egg)
if not os.path.exists(egg):
raise IOError('Could not build the egg.')
def _do_download(version, download_base, to_dir, download_delay):
egg = os.path.join(to_dir, 'distribute-%s-py%d.%d.egg'
% (version, sys.version_info[0], sys.version_info[1]))
if not os.path.exists(egg):
tarball = download_setuptools(version, download_base,
to_dir, download_delay)
_build_egg(egg, tarball, to_dir)
sys.path.insert(0, egg)
import setuptools
setuptools.bootstrap_install_from = egg
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, download_delay=15, no_fake=True):
# making sure we use the absolute path
to_dir = os.path.abspath(to_dir)
was_imported = 'pkg_resources' in sys.modules or \
'setuptools' in sys.modules
try:
try:
import pkg_resources
if not hasattr(pkg_resources, '_distribute'):
if not no_fake:
_fake_setuptools()
raise ImportError
except ImportError:
return _do_download(version, download_base, to_dir, download_delay)
try:
pkg_resources.require("distribute>="+version)
return
except pkg_resources.VersionConflict:
e = sys.exc_info()[1]
if was_imported:
sys.stderr.write(
"The required version of distribute (>=%s) is not available,\n"
"and can't be installed while this script is running. Please\n"
"install a more recent version first, using\n"
"'easy_install -U distribute'."
"\n\n(Currently using %r)\n" % (version, e.args[0]))
sys.exit(2)
else:
del pkg_resources, sys.modules['pkg_resources'] # reload ok
return _do_download(version, download_base, to_dir,
download_delay)
except pkg_resources.DistributionNotFound:
return _do_download(version, download_base, to_dir,
download_delay)
finally:
if not no_fake:
_create_fake_setuptools_pkg_info(to_dir)
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, delay=15):
"""Download distribute from a specified location and return its filename
`version` should be a valid distribute version number that is available
as an egg for download under the `download_base` URL (which should end
with a '/'). `to_dir` is the directory where the egg will be downloaded.
`delay` is the number of seconds to pause before an actual download
attempt.
"""
# making sure we use the absolute path
to_dir = os.path.abspath(to_dir)
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
tgz_name = "distribute-%s.tar.gz" % version
url = download_base + tgz_name
saveto = os.path.join(to_dir, tgz_name)
src = dst = None
if not os.path.exists(saveto): # Avoid repeated downloads
try:
log.warn("Downloading %s", url)
src = urlopen(url)
# Read/write all in one block, so we don't create a corrupt file
# if the download is interrupted.
data = src.read()
dst = open(saveto, "wb")
dst.write(data)
finally:
if src:
src.close()
if dst:
dst.close()
return os.path.realpath(saveto)
def _no_sandbox(function):
def __no_sandbox(*args, **kw):
try:
from setuptools.sandbox import DirectorySandbox
if not hasattr(DirectorySandbox, '_old'):
def violation(*args):
pass
DirectorySandbox._old = DirectorySandbox._violation
DirectorySandbox._violation = violation
patched = True
else:
patched = False
except ImportError:
patched = False
try:
return function(*args, **kw)
finally:
if patched:
DirectorySandbox._violation = DirectorySandbox._old
del DirectorySandbox._old
return __no_sandbox
def _patch_file(path, content):
"""Will backup the file then patch it"""
existing_content = open(path).read()
if existing_content == content:
# already patched
log.warn('Already patched.')
return False
log.warn('Patching...')
_rename_path(path)
f = open(path, 'w')
try:
f.write(content)
finally:
f.close()
return True
_patch_file = _no_sandbox(_patch_file)
def _same_content(path, content):
return open(path).read() == content
def _rename_path(path):
new_name = path + '.OLD.%s' % time.time()
log.warn('Renaming %s into %s', path, new_name)
os.rename(path, new_name)
return new_name
def _remove_flat_installation(placeholder):
if not os.path.isdir(placeholder):
log.warn('Unkown installation at %s', placeholder)
return False
found = False
for file in os.listdir(placeholder):
if fnmatch.fnmatch(file, 'setuptools*.egg-info'):
found = True
break
if not found:
log.warn('Could not locate setuptools*.egg-info')
return
log.warn('Removing elements out of the way...')
pkg_info = os.path.join(placeholder, file)
if os.path.isdir(pkg_info):
patched = _patch_egg_dir(pkg_info)
else:
patched = _patch_file(pkg_info, SETUPTOOLS_PKG_INFO)
if not patched:
log.warn('%s already patched.', pkg_info)
return False
# now let's move the files out of the way
for element in ('setuptools', 'pkg_resources.py', 'site.py'):
element = os.path.join(placeholder, element)
if os.path.exists(element):
_rename_path(element)
else:
log.warn('Could not find the %s element of the '
'Setuptools distribution', element)
return True
_remove_flat_installation = _no_sandbox(_remove_flat_installation)
def _after_install(dist):
log.warn('After install bootstrap.')
placeholder = dist.get_command_obj('install').install_purelib
_create_fake_setuptools_pkg_info(placeholder)
def _create_fake_setuptools_pkg_info(placeholder):
if not placeholder or not os.path.exists(placeholder):
log.warn('Could not find the install location')
return
pyver = '%s.%s' % (sys.version_info[0], sys.version_info[1])
setuptools_file = 'setuptools-%s-py%s.egg-info' % \
(SETUPTOOLS_FAKED_VERSION, pyver)
pkg_info = os.path.join(placeholder, setuptools_file)
if os.path.exists(pkg_info):
log.warn('%s already exists', pkg_info)
return
log.warn('Creating %s', pkg_info)
f = open(pkg_info, 'w')
try:
f.write(SETUPTOOLS_PKG_INFO)
finally:
f.close()
pth_file = os.path.join(placeholder, 'setuptools.pth')
log.warn('Creating %s', pth_file)
f = open(pth_file, 'w')
try:
f.write(os.path.join(os.curdir, setuptools_file))
finally:
f.close()
_create_fake_setuptools_pkg_info = _no_sandbox(_create_fake_setuptools_pkg_info)
def _patch_egg_dir(path):
# let's check if it's already patched
pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')
if os.path.exists(pkg_info):
if _same_content(pkg_info, SETUPTOOLS_PKG_INFO):
log.warn('%s already patched.', pkg_info)
return False
_rename_path(path)
os.mkdir(path)
os.mkdir(os.path.join(path, 'EGG-INFO'))
pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')
f = open(pkg_info, 'w')
try:
f.write(SETUPTOOLS_PKG_INFO)
finally:
f.close()
return True
_patch_egg_dir = _no_sandbox(_patch_egg_dir)
def _before_install():
log.warn('Before install bootstrap.')
_fake_setuptools()
def _under_prefix(location):
if 'install' not in sys.argv:
return True
args = sys.argv[sys.argv.index('install')+1:]
for index, arg in enumerate(args):
for option in ('--root', '--prefix'):
if arg.startswith('%s=' % option):
top_dir = arg.split('root=')[-1]
return location.startswith(top_dir)
elif arg == option:
if len(args) > index:
top_dir = args[index+1]
return location.startswith(top_dir)
if arg == '--user' and USER_SITE is not None:
return location.startswith(USER_SITE)
return True
def _fake_setuptools():
log.warn('Scanning installed packages')
try:
import pkg_resources
except ImportError:
# we're cool
log.warn('Setuptools or Distribute does not seem to be installed.')
return
ws = pkg_resources.working_set
try:
setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools',
replacement=False))
except TypeError:
# old distribute API
setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools'))
if setuptools_dist is None:
log.warn('No setuptools distribution found')
return
# detecting if it was already faked
setuptools_location = setuptools_dist.location
log.warn('Setuptools installation detected at %s', setuptools_location)
# if --root or --preix was provided, and if
# setuptools is not located in them, we don't patch it
if not _under_prefix(setuptools_location):
log.warn('Not patching, --root or --prefix is installing Distribute'
' in another location')
return
# let's see if its an egg
if not setuptools_location.endswith('.egg'):
log.warn('Non-egg installation')
res = _remove_flat_installation(setuptools_location)
if not res:
return
else:
log.warn('Egg installation')
pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO')
if (os.path.exists(pkg_info) and
_same_content(pkg_info, SETUPTOOLS_PKG_INFO)):
log.warn('Already patched.')
return
log.warn('Patching...')
# let's create a fake egg replacing setuptools one
res = _patch_egg_dir(setuptools_location)
if not res:
return
log.warn('Patched done.')
_relaunch()
def _relaunch():
log.warn('Relaunching...')
# we have to relaunch the process
# pip marker to avoid a relaunch bug
if sys.argv[:3] == ['-c', 'install', '--single-version-externally-managed']:
sys.argv[0] = 'setup.py'
args = [sys.executable] + sys.argv
sys.exit(subprocess.call(args))
def _extractall(self, path=".", members=None):
"""Extract all members from the archive to the current working
directory and set owner, modification time and permissions on
directories afterwards. `path' specifies a different directory
to extract to. `members' is optional and must be a subset of the
list returned by getmembers().
"""
import copy
import operator
from tarfile import ExtractError
directories = []
if members is None:
members = self
for tarinfo in members:
if tarinfo.isdir():
# Extract directories with a safe mode.
directories.append(tarinfo)
tarinfo = copy.copy(tarinfo)
tarinfo.mode = 448 # decimal for oct 0700
self.extract(tarinfo, path)
# Reverse sort directories.
if sys.version_info < (2, 4):
def sorter(dir1, dir2):
return cmp(dir1.name, dir2.name)
directories.sort(sorter)
directories.reverse()
else:
directories.sort(key=operator.attrgetter('name'), reverse=True)
# Set correct owner, mtime and filemode on directories.
for tarinfo in directories:
dirpath = os.path.join(path, tarinfo.name)
try:
self.chown(tarinfo, dirpath)
self.utime(tarinfo, dirpath)
self.chmod(tarinfo, dirpath)
except ExtractError:
e = sys.exc_info()[1]
if self.errorlevel > 1:
raise
else:
self._dbg(1, "tarfile: %s" % e)
def main(argv, version=DEFAULT_VERSION):
"""Install or upgrade setuptools and EasyInstall"""
tarball = download_setuptools()
_install(tarball)
if __name__ == '__main__':
main(sys.argv[1:])

294
fr.po
View File

@ -1,40 +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.1\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-10-14 20:56+0200\n"
"Last-Translator: Matteo Cypriani <mcy@lm7.fr>\n"
"Language: fr\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"
"Language-Team: \n"
"X-Generator: Poedit 2.2\n"
#: gcp:46
#: gcp:43
msgid "Error during import"
msgstr "Erreur pendant l'import de bibliothèques"
#: gcp:47
#: gcp:44
msgid "Please check dependecies:"
msgstr "Merci de vérifier les dépendances :"
msgstr "Merci de vérifier les dépendances"
#: gcp:54
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 depuishttps://pypi."
"org/"
"«ProgressBar» n'est pas disponible, merci de le télécharger à http://pypi."
"python.org/pypi/progressbar"
#: gcp:55
#: gcp:51
msgid ""
"Progress bar deactivated\n"
"--\n"
@ -42,247 +40,235 @@ msgstr ""
"Barre de progression désactivée\n"
"--\n"
#: gcp:90
#: 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..."
msgstr "Initialisation de «DbusObject»"
#: gcp:111
#: gcp:106
msgid "INTERNAL ERROR: invalid arguments"
msgstr "ERREUR INTERNE : arguments invalides"
msgstr "ERREUR INTERNE: arguments invalides"
#: gcp:116
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:165
msgid "/!\\ THE FOLLOWING FILES WERE *NOT* SUCCESSFULY COPIED:"
msgstr "/!\\ LES FICHIERS SUIVANTS *N'ONT PAS* ÉTÉ COPIÉS:"
#: gcp:171
msgid "/!\\ THE FOLLOWING FILES WERE *NOT* SUCCESSFULY COPIED:"
msgstr "/!\\ LES FICHIERS SUIVANTS N'ONT *PAS* ÉTÉ COPIÉS :"
msgid "The following files were copied, but some errors happened:"
msgstr ""
"Les fichiers suivant ont été copiés, mais quelques erreurs sont survenues:"
#: gcp:177
msgid "The following files were copied, but some errors happened:"
msgstr "Les fichiers suivant ont été copiés, mais des erreurs sont survenues :"
#: gcp:183
#, python-format
msgid "Please check journal: %s"
msgstr "Merci de vérifier le journal : %s"
msgstr "Merci de vérifier le journal: %s"
#: gcp:205
#: gcp:199
msgid "gcp launched"
msgstr "gcp lancé"
#: gcp:213
#: gcp:207
msgid "Init DBus..."
msgstr "Initialisation de DBus..."
msgstr "Initialisation de Dbus..."
#: gcp:244
#: gcp:237
msgid "Can't read mounts table"
msgstr "Impossible de lire la table des montages"
#: gcp:251
#: 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:258
#: 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:286
#: 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:289
#, python-format
msgid "Can't access %(dirpath)s: %(exception)s"
msgstr "Impossible d'accéder à %(dirpath)s : %(exception)s"
#: gcp:301
#: gcp:283
#, python-format
msgid "Invalid dest_path: %s"
msgstr "Chemin de destination invalide : %s"
msgstr "Chemin de destination invalide: %s"
#: gcp:306
#: 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:293
#, python-format
msgid "omitting directory \"%s\""
msgstr "Répertoire \"%s\" ignoré"
#: gcp:310
#, python-format
msgid "omitting directory \"%s\""
msgstr "répertoire \"%s\" ignoré"
#: gcp:348
#, 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:368
#: gcp:328
#, python-format
msgid "COPYING %(source)s ==> %(dest)s"
msgstr "COPIE %(source)s ==> %(dest)s"
#: gcp:462
#: gcp:429
#, python-format
msgid "%.2f PiB"
msgstr "%.2f Pio"
#: gcp:464
#: gcp:431
#, python-format
msgid "%.2f TiB"
msgstr "%.2f Tio"
#: gcp:466
#: gcp:433
#, python-format
msgid "%.2f GiB"
msgstr "%.2f Gio"
#: gcp:468
#: gcp:435
#, python-format
msgid "%.2f MiB"
msgstr "%.2f Mio"
#: gcp:470
#: gcp:437
#, python-format
msgid "%.2f KiB"
msgstr "%.2f Kio"
#: gcp:471
#: gcp:439
#, python-format
msgid "%i B"
msgstr "%i o"
#: gcp:479 gcp:485
#: gcp:447 gcp:452
#, python-format
msgid "Copying %s"
msgstr "Copie de %s"
#: gcp:515 gcp:548
#: 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:525
#: gcp:489
msgid "Saved sources:"
msgstr "Liste de sources sauvées :"
msgstr "Liste de sources sauvées:"
#: gcp:539
#: 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:578
msgid "force overwriting of existing files"
msgstr "forcer le remplacement des fichiers déjà existants"
#: gcp:582
msgid "always follow symbolic links in sources"
msgstr "toujours suivre les liens symboliques"
#: gcp:586
msgid "never follow symbolic links in sources"
msgstr "ne pas suivre les liens symboliques"
#: gcp:590
#, python-format
msgid "same as --preserve=%s"
msgstr "raccourci pour --preserve=%s"
#: gcp:594
#, 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:599
#: gcp:539
msgid "copy directories recursively"
msgstr "copier les répertoire récursivement"
msgstr "copie les répertoire récursivement"
#: gcp:603
msgid "display what is being done"
msgstr "afficher les opérations effectuées"
#: gcp:542
msgid "force overwriting of existing files"
msgstr "force le remplacement des fichiers déjà existants"
#: gcp:614
msgid ""
"fix file names incompatible with the destination file "
"system (default: auto)"
#: gcp:545
msgid "preserve the specified attributes"
msgstr "garde les attributs spécifiés"
#: gcp:551
msgid "don't fix filesystem name incompatibily"
msgstr ""
"corriger les noms de fichiers incompatibles avec le système de fichiers "
"cible (défaut : auto)"
"Ne corrige pas les incompatibilités des noms pour le système de fichiers"
#: gcp:619
msgid ""
"[DEPRECATED] same as --fix-filename=no (overrides --fix-"
"filenames)"
#: 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
msgid "Save source arguments and replace memory if it already exists"
msgstr ""
"[OBSOLÈTE] identique à --fix-filenames=no (--fix-filenames sera ignoré)"
"Sauvegarde la liste des fichiers sources et la remplace si elle existe déjà"
#: gcp:624
msgid "disable progress bar"
msgstr "désactiver la barre de progression"
#: gcp:568
msgid "Load source arguments"
msgstr "Réutilise les fichiers sources à copier"
#: gcp:631
msgid "save sources arguments"
msgstr "sauvegarder la liste des fichiers source"
#: gcp:571
msgid "delete saved sources"
msgstr "Supprime la liste des fichiers sources"
#: gcp:635
msgid "save sources arguments and replace memory if it already exists"
#: gcp:574
msgid "List names of saved sources"
msgstr "Liste les noms des listes de fichiers sources"
#: gcp:577
msgid "List names of saved sources and files in it"
msgstr ""
"sauvegarder la liste des fichiers source et la remplacer si elle existe déjà"
#: gcp:639
msgid "load sources arguments"
msgstr "réutiliser les fichiers source à copier"
#: gcp:643
msgid "delete saved sources list"
msgstr "supprimer la liste des fichiers source"
#: gcp:647
msgid "list names of saved sources"
msgstr "afficher les noms des listes de fichiers source"
#: gcp:651
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:663
#: gcp:585
msgid "Progress bar is not available, deactivating"
msgstr "La barre de progression n'est pas disponible, désactivation"
#: gcp:687
#, python-format
msgid "Invalid --preserve value '%s'"
msgstr "Valeur de --preserve invalide « %s »"
#: gcp:595
msgid ""
"Invalide --preserve value\n"
"valid values are:"
msgstr ""
"La valeur de «--preserve» est invalide\n"
"Les valeurs valides sont:"
#: gcp:714
#: 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:720
#: gcp:622
msgid "Wrong number of arguments"
msgstr "Nombre d'arguments invalide"
#: gcp:722
#: gcp:624
#, python-format
msgid "adding args to gcp: %s"
msgstr "ajout des arguments à gcp : %s"
msgstr "ajout des arguments à gcp: %s"
#: gcp:731
#: 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"

452
gcp
View File

@ -1,11 +1,10 @@
#!/usr/bin/env python3
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
gcp: Gcp CoPier
Copyright (c) 2010, 2011 Jérôme Poisson <goffi@goffi.org>
gcp: Goffi's CoPier
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, 2019 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,65 +20,66 @@ 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", unicode=True)
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 os,os.path
from optparse import OptionParser, OptionGroup #To be replaced by argparse ASAP
import cPickle as pickle
try:
from gi.repository import GLib
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
import gobject
#DBus
import dbus, dbus.glib
import dbus.service
import dbus
except ImportError as e:
import dbus.mainloop.glib
except ImportError,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/"))
except ImportError, e:
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 (Gcp CoPier)"
NAME = "gcp (Goffi's copier)"
NAME_SHORT = "gcp"
VERSION = '0.2.1'
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"
const_SAVED_LIST = const_FILES_DIR + "/saved_list"
class DbusObject(dbus.service.Object):
def __init__(self, gcp, bus, path):
@ -104,19 +104,15 @@ class DbusObject(dbus.service.Object):
@return: success (boolean) and error message if any (string)"""
try:
args = pickle.loads(str(args))
except TypeError as e:
pickle.UnpicklingError = e
except TypeError, pickle.UnpicklingError:
return (False, _("INTERNAL ERROR: invalid arguments"))
try:
source_dir = pickle.loads(str(source_dir))
except TypeError as e:
pickle.UnpicklingError = e
except TypeError, pickle.UnpicklingError:
return (False, _("INTERNAL ERROR: invalid source_dir"))
return self._gcp.parseArguments(args, source_dir)
class Journal():
def __init__(self, path=const_JOURNAL_PATH):
self.journal_path = os.path.expanduser(path)
self.journal_fd = open(self.journal_path,'w') #TODO: check and maybe save previous journals
@ -183,6 +179,8 @@ class Journal():
info(_("Please check journal: %s") % self.journal_path)
class GCP():
def __init__(self):
@ -197,7 +195,7 @@ class GCP():
dbus_interface=const_DBUS_INTERFACE)
self._main_instance = False
except dbus.exceptions.DBusException as e:
except dbus.exceptions.DBusException,e:
if e._dbus_error_name=='org.freedesktop.DBus.Error.ServiceUnknown':
self.launchDbusMainInstance()
debug (_("gcp launched"))
@ -229,15 +227,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:
with open("/proc/mounts",'rb') 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
@ -246,22 +243,22 @@ 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.decode('utf-8','replace'),
"dest_path":dest_path.decode('utf-8','replace'),
"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})
except OSError,e:
error(_("Can't copy %(path)s: %(exception)s") % {'path':path.decode('utf-8','replace'), 'exception':e.strerror})
def __appendDirToList(self, dirpath, dest_path, options):
"""Add recursively directory to the copy list
@param path: absolute path of dir
@param options: options as return by optparse"""
#We first check that the dest path exists, and create it if needed
dest_path = self.__fix_filenames(dest_path, options, no_journal=True)
dest_path = self.__filename_fix(dest_path, options, no_journal=True)
if not os.path.exists(dest_path):
debug ("Creating directory %s" % dest_path)
os.makedirs(dest_path) #TODO: check permissions
@ -271,19 +268,21 @@ class GCP():
for filename in os.listdir(dirpath):
filepath = os.path.join(dirpath,filename)
if os.path.islink(filepath) and not options.dereference:
debug ("Skippink symbolic dir: %s" % filepath)
debug ("Skippink symbolic dir: %s" % filepath.decode('utf-8','replace'))
continue
if os.path.isdir(filepath):
full_dest_path = os.path.join(dest_path,filename)
self.__appendDirToList(filepath, full_dest_path, options)
else:
self.__appendToList(filepath, dest_path, options)
except OSError as e:
except OSError,e:
try:
error(_("Can't append %(path)s to copy list: %(exception)s") % {'path':filepath, 'exception':e.strerror})
error(_("Can't append %(path)s to copy list: %(exception)s") % {'path':filepath.decode('utf-8','replace'),
'exception':e.strerror})
except NameError:
#We can't list the dir
error(_("Can't access %(dirpath)s: %(exception)s") % {'dirpath':dirpath, 'exception':e.strerror})
error(_("Can't access %(dirpath)s: %(exception)s") % {'dirpath':dirpath.decode('utf-8','replace'),
'exception':e.strerror})
def __checkArgs(self, options, source_dir, args):
"""Check thats args are files, and add them to copy list
@ -294,17 +293,17 @@ class GCP():
len_args = len(args)
try:
dest_path = os.path.normpath(os.path.join(source_dir, args.pop()))
except OSError as e:
except OSError,e:
error (_("Invalid dest_path: %s"),e)
for path in args:
abspath = os.path.normpath(os.path.join(os.path.expanduser(source_dir), path))
if not os.path.exists(abspath):
warning(_("The path given in arg doesn't exist or is not accessible: %s") % abspath)
warning(_("The path given in arg doesn't exist or is not accessible: %s") % abspath.decode('utf-8','replace'))
else:
if os.path.isdir(abspath):
if not options.recursive:
warning (_('omitting directory "%s"') % abspath)
warning (_('omitting directory "%s"') % abspath.decode('utf-8','replace'))
else:
_basename=os.path.basename(os.path.normpath(path))
full_dest_path = dest_path if options.directdir else os.path.normpath(os.path.join(dest_path, _basename))
@ -313,58 +312,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.
@return: True a file was added, False otherwise."""
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.decode('utf-8','replace'))
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.decode('utf-8','replace'),
"dest":dest_file.decode('utf-8','replace')})
return True
else:
#Nothing left to copy, we quit
if self.progress:
self.__pbar_finish()
self.journal.showErrors()
self.loop.quit()
return False
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)
if options.dest_file:
dest_file = self.__fix_filenames(options.dest_file, options)
else:
dest_file = self.__fix_filenames(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
GLib.io_add_watch(source_fd, GLib.IO_IN,self._copyFile,
(dest_fd, options),
priority=GLib.PRIORITY_DEFAULT)
if not self.progress:
info(_("COPYING %(source)s ==> %(dest)s")
% {"source":source_file, "dest":dest_file})
return True
def __copyFailed(self, reason, source_fd, dest_fd):
"""Write the failure in the journal and close files descriptors"""
@ -374,6 +364,8 @@ class GCP():
source_fd.close()
dest_fd.close()
def _copyFile(self, source_fd, condition, data):
"""Actually copy the file, callback used with io_add_watch
@param source_fd: file descriptor of the file to copy
@ -412,7 +404,7 @@ class GCP():
except KeyboardInterrupt:
self._userInterruption()
def __fix_filenames(self, filename, options, no_journal=False):
def __filename_fix(self, filename, options, no_journal=False):
"""Fix filenames incompatibilities/mistake according to options
@param filename: full path to the file
@param options: options as parsed on command line
@ -420,7 +412,7 @@ class GCP():
@return: fixed filename"""
fixed_filename = filename
if options.fix_filenames == 'force' or (options.fix_filenames == 'auto' and self.getFsType(filename) == 'vfat'):
if options.fs_fix == 'force' or (options.fs_fix == 'auto' and self.getFsType(filename) == 'vfat'):
fixed_filename = filename.replace('\\','_')\
.replace(':',';')\
.replace('*','+')\
@ -448,22 +440,24 @@ class GCP():
os.chown(dest_file, st_file.st_uid, st_file.st_gid)
elif preserve == 'timestamps':
os.utime(dest_file, (st_file.st_atime, st_file.st_mtime))
except OSError as e:
except OSError,e:
self.journal.error("preserve-"+preserve)
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"""
@ -471,16 +465,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)
@ -506,7 +496,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]
@ -515,9 +505,10 @@ class GCP():
if not args:
exit(0)
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)
@ -529,16 +520,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]
@ -553,106 +544,74 @@ class GCP():
@return: a tuple (boolean, message) where the boolean is the success of the arguments
validation, and message is the error message to print when necessary"""
_usage="""
%(prog)s [options] FILE DEST
%(prog)s [options] FILE1 [FILE2 ...] DEST-DIR
%prog [options] FILE DEST
%prog [options] FILE1 [FILE2 ...] DEST-DIR
%prog --help for options list
"""
for idx in range(len(full_args)):
full_args[idx] = full_args[idx].encode('utf-8')
if isinstance(full_args[idx], unicode):
#We don't want unicode as some filenames can be invalid unicode
full_args[idx] = full_args[idx].encode('utf-8')
parser = ArgumentParser(usage=_usage,
formatter_class=RawDescriptionHelpFormatter)
parser = OptionParser(usage=_usage,version=ABOUT)
parser.add_argument("-V", "--version",
action="version", version=ABOUT
)
parser.add_option("-r", "--recursive", action="store_true", default=False,
help=_("copy directories recursively"))
group_cplike = parser.add_argument_group("cp-like options")
group_cplike.add_argument("-f", "--force",
action="store_true", default=False,
help=_("force overwriting of existing files")
)
group_cplike.add_argument("-L", "--dereference",
action="store_true", default=False,
help=_("always follow symbolic links in sources")
)
group_cplike.add_argument("-P", "--no-dereference",
action="store_false", dest='dereference',
help=_("never follow symbolic links in sources")
)
group_cplike.add_argument("-p",
action="store_true", default=False,
help=_("same as --preserve=%s" % const_PRESERVE_p)
)
group_cplike.add_argument("--preserve",
action="store", default='',
help=_("preserve specified attributes; accepted values: \
'all', or one or more amongst %s") % str(const_PRESERVE)
)
group_cplike.add_argument("-r", "-R", "--recursive",
action="store_true", default=False,
help=_("copy directories recursively")
)
group_cplike.add_argument("-v", "--verbose",
action="store_true", default=False,
help=_("display what is being done")
)
parser.add_argument_group(group_cplike)
parser.add_option("-f", "--force", action="store_true", default=False,
help=_("force overwriting of existing files"))
group_gcpspecific = parser.add_argument_group("gcp-specific options")
#parser.add_argument("--no-unicode-fix",
# action="store_false", dest='unicode_fix', default=True,
# help=_("don't fix name encoding errors") #TODO
#)
group_gcpspecific.add_argument("--fix-filenames",
choices = const_FS_FIX, dest='fix_filenames', default='auto',
help=_("fix file names incompatible with the destination \
file system (default: auto)")
)
group_gcpspecific.add_argument("--no-fs-fix",
action="store_true", dest='no_fs_fix', default=False,
help=_("[DEPRECATED] same as --fix-filename=no (overrides \
--fix-filenames)")
)
group_gcpspecific.add_argument("--no-progress",
action="store_false", dest="progress", default=True,
help=_("disable progress bar")
)
parser.add_argument_group(group_gcpspecific)
parser.add_option("--preserve", action="store", default='mode,ownership,timestamps',
help=_("preserve the specified attributes"))
group_saving = parser.add_argument_group("sources saving")
group_saving.add_argument("--sources-save",
action="store",
help=_("save sources arguments")
)
group_saving.add_argument("--sources-replace",
action="store",
help=_("save sources arguments and replace memory if it already exists")
)
group_saving.add_argument("--sources-load",
action="store",
help=_("load sources arguments")
)
group_saving.add_argument("--sources-del",
action="store",
help=_("delete saved sources list")
)
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)
parser.add_option("-L", "--dereference", action="store_true", default=False,
help=_("always follow symbolic links in sources"))
(options, args) = parser.parse_known_args()
parser.add_option("-P", "--no-dereference", action="store_false", dest='dereference',
help=_("never follow symbolic links in sources"))
# True only in the special case: we are copying a dir and it doesn't
# exists:
options.directdir = False
#parser.add_option("--no-unicode-fix", action="store_false", dest='unicode_fix', default=True,
# help=_("don't fix name encoding errors")) #TODO
# options check
parser.add_option("--fs-fix", action="store", dest='fs_fix', default='auto',
help=_("fix filesystem name incompatibily; can be 'auto' (default), 'force' or 'no'"))
parser.add_option("--no-fs-fix", action="store_true", dest='no_fs_fix', default=False,
help=_("same as --fs-fix=no (overrides --fs-fix)"))
parser.add_option("--no-progress", action="store_false", dest="progress", default=True,
help=_("deactivate progress bar"))
parser.add_option("-v", "--verbose", action="store_true", default=False,
help=_("Show what is currently done"))
group_saving = OptionGroup(parser, "sources saving")
group_saving.add_option("--sources-save", action="store",
help=_("Save source arguments"))
group_saving.add_option("--sources-replace", action="store",
help=_("Save source arguments and replace memory if it already exists"))
group_saving.add_option("--sources-load", action="store",
help=_("Load source arguments"))
group_saving.add_option("--sources-del", action="store",
help=_("delete saved sources"))
group_saving.add_option("--sources-list", action="store_true", default=False,
help=_("List names of saved sources"))
group_saving.add_option("--sources-full-list", action="store_true", default=False,
help=_("List names of saved sources and files in it"))
parser.add_option_group(group_saving)
(options, args) = parser.parse_args(full_args)
options.directdir = False #True only in the special case: we are copying a dir and it doesn't exists
#options check
if options.progress and not pbar_available:
warning (_("Progress bar is not available, deactivating"))
options.progress = self.progress = False
@ -663,28 +622,22 @@ class GCP():
logging.getLogger().setLevel(logging.DEBUG)
if options.no_fs_fix:
options.fix_filenames = 'no'
options.fs_fix = 'no'
else:
if not options.fs_fix in const_FS_FIX:
error (_("Invalid --fs-fix value\nvalid values are:"))
for value in const_FS_FIX:
error('- %s' % value)
exit(1)
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
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
self.__sourcesSaving(options, args)
@ -713,11 +666,11 @@ class GCP():
if len(args) < 2:
_error_msg = _("Wrong number of arguments")
return (False, _error_msg)
debug(_("adding args to gcp: %s") % args)
debug(_("adding args to gcp: %s") % str(args).decode('utf-8','replace'))
self.__checkArgs(options, source_dir, args)
if not self.__launched:
self.journal = Journal()
GLib.idle_add(self.__copyNextFile)
gobject.idle_add(self.__copyNextFile)
self.__launched = True
return (True,'')
@ -727,7 +680,7 @@ class GCP():
def go(self):
"""Launch main loop"""
self.loop = GLib.MainLoop()
self.loop = gobject.MainLoop()
try:
self.loop.run()
except KeyboardInterrupt:
@ -746,3 +699,4 @@ if __name__ == "__main__":
exit(1)
if gcp.journal.partial:
exit(2)

162
gcp.1
View File

@ -2,7 +2,7 @@
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH GCP 1 "October 14, 2018"
.TH GCP 1 "June 04, 2011"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
@ -15,9 +15,6 @@
.\" .br insert line break
.\" .sp <n> insert n+1 empty lines
.\" for manpage-specific macros, see man(7)
.\" TeX users may be more comfortable with the \fB<whatever>\fP and
.\" \fI<whatever>\fP escape sequences to invode bold face and italics,
.\" respectively.
.SH NAME
gcp \- Advanced command-line file copier
.SH SYNOPSIS
@ -31,109 +28,74 @@ gcp \- Advanced command-line file copier
.RI [ FILE2 ... ]
.I DEST-DIR
.SH DESCRIPTION
\fBgcp\fP is a file copier, loosely inspired by cp, but with high level
functionalities like:
.IP \(bu 2
transfer progression indication
.IP \(bu
continuous copying when there is an issue: it skips the problematic file and
goes on
.IP \(bu
copy status logging: which files were effectively copied
.IP \(bu
name mangling to handle target filesystem limitations (e.g. removing
incompatible chars like "?" or "*" on FAT filesystems)
.IP \(bu
forced copy serialization: new files to copy are added to a global queue to
avoid hard drive head seeks
.IP \(bu
transfer list management: gcp can save a list of files to copy and reuse it
later
.IP \(bu
approximate option compatibility with cp (approximate because the behaviour is
not exactly the same, see below)
This manual page documents briefly the
.B gcp
command.
.PP
.\" TeX users may be more comfortable with the \fB<whatever>\fP and
.\" \fI<whatever>\fP escape sequences to invode bold face and italics,
.\" respectively.
\fBgcp\fP is a file copier, loosely inspired by cp, but with high level functionalities like:
\- transfer progression indication
\- continuous copying when there is an issue: it skips the problematic file and goes on
\- copy status logging: which files were effectively copied
\- name mangling to handle target filesystem limitations (e.g. removing incompatible chars like "?" or "*" on vfat)
\- forced copy serialization: new files to copy are added to a global queue to avoid hard drive head seeks
\- transfer list management: gcp can save a list of files to copy and reuse it later
\- approximate option compatibility with cp (approximate because the behaviour is not exactly the same, see below)
.SH OPTIONS
These programs follow the usual GNU command line syntax, with long
options starting with two dashes (`-').
By default, calling gcp is equivalent to calling gcp \-\-preserve=mode,ownership,timestamps.
.PP
A summary of options is included below.
.SS General options
.SS "General options"
.TP
.B \-\-version
Show version of program and exit.
.TP
.B \-h, \-\-help
Show summary of options.
.TP
.B \-V, \-\-version
Show program version and copyright information and exit.
.SS cp-like options
.B \-r, \-\-recursive
Copy directories recursively.
.TP
.B \-L, \-\-dereference
always follow symbolic links in sources
.TP
.B \-P, \-\-no\-dereference
never follow symbolic links in sources
.TP
.B \-f, \-\-force
Overwrite existing files.
.TP
.B \-L, \-\-dereference
Always follow symbolic links in sources.
.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.
.TP
.B \-P, \-\-no\-dereference
Never follow symbolic links in sources.
.TP
.B \-p
Same as \fB\-\-preserve=mode,ownership,timestamps\fP
.TP
.B \-\-preserve=<\fIattributes\fP>
Preserve specified attributes. Attributes can be \fImode\fP, \fIownership\fP
and \fItimestamps\fP.
When several attributes are passed, they need to be separated by commas.
Please note that timestamps preservation has some limits, see section
\fILIMITATIONS\fP.
.TP
.B \-r, \-R, \-\-recursive
Copy directories recursively.
.TP
.B \-v, \-\-verbose
Display what is being done.
.SS gcp-specific options
.TP
.B \-\-fix\-filenames=<\fIforce\fP|\fIauto\fP|\fIno\fP>
gcp has the ability to modify the destination file name if the target file
system would not accept the original file name.
Offending characters will be replaced with similar-looking ones.
.IP
This option accept the following values:
.RS
.TP
\fIauto\fP (default)
gcp will attempt to be smart, i.e. detect incompatibilities and fix them as-needed.
.TP
\fIforce\fP
Always fix file names that could cause problems on any known filesystem or OS.
This is useful e.g. with NTFS, see \fINOTE ON NTFS\fP below.
.TP
\fIno\fP
Renaming is disabled entirely.
.RE
.IP
Currently, gcp is only aware of FAT incompatibilities:
\'\\\', \':\', \'*\', \'?\', \'"\', \'<\', \'>\' and \'|\'.
.TP
.B \-\-no\-fs\-fix (DEPRECATED)
Same as \fB\-\-fix\-filenames=no\fP.
This option will be removed in a future release.
.B \-\-no\-fs\-fix
Don't fix file system naming incompatibilities.
.TP
.B \-\-no\-progress
Disable progress bar.
.SS Sources saving
.TP
.B \-\-sources\-save=\fISOURCES\fP
Save the list of source files in a list named \fISOURCES\fP.
.B \-v, \-\-verbose
Display what is being done.
.SS "Sources saving"
.TP
.B \-\-sources\-replace=\fISOURCES\fP
Save the list of source files in a list named \fISOURCES\fP;
the file is overwritten it already exists.
.B \-\-sources\-save=SOURCES_SAVE
Save the list of source files in a list named SOURCES_SAVE.
.TP
.B \-\-sources\-load=\fISOURCES\fP
Use the list of source files named \fISOURCES\fP.
.B \-\-sources\-replace=SOURCES_REPLACE
Save the list of source files in a list named SOURCES_REPLACE and
replace it if it already exists.
.TP
.B \-\-sources\-del=\fISOURCES\fP
Delete the list of source files named \fISOURCES\fP.
.B \-\-sources\-load=SOURCES_LOAD
Reuse the list of source file named SOURCES_LOAD.
.TP
.B \-\-sources\-del=SOURCES_DEL
Delete the list of source files named SOURCES_DEL.
.TP
.B \-\-sources\-list
List the names of source file lists.
@ -143,33 +105,21 @@ List the names of source file lists, including their content.
.SH EXIT STATUS
The exit status can be:
.IP \[bu] 2
\fB0\fP if files have been copied correctly or if another instance of gcp is
already running and will do the copy.
\fB0\fP if files have been copied correctly or if another instance of gcp is already running and will do the copy.
.IP \[bu]
\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
Timestamps preservation with \fB\-\-preserve\fP option is limited by the
\fIos\fP 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 issue can be seen at
http://bugs.python.org/issue11457.
.PP
The \fB\-\-preserve\fP option cannot currently be used without an attribute
list (\fBgcp \-\-preserve foo bar\fP will behave as \fBgcp \-\-preserve=foo
bar\fP). Use the \fB\-p\fP switch instead.
.SH NOTE ON NTFS
NTFS will not enforce the same file name limitations than FAT, but files that
would not be accepted on a FAT filesystem will still cause problems on Windows.
Hence, it is recommended to use \-\-fix-filenames=force when copying to NTFS
(when Windows compatibility is desired, anyway).
.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
issue can be seen at http://bugs.python.org/issue11457.
.SH SEE ALSO
.BR cp (1).
.br
.SH AUTHOR
gcp was written by Jérôme Poisson <goffi@goffi.org>.
It is currently maintained by Matteo Cypriani <mcy@lm7.fr>.
.PP
This manual page was initially written by Thomas Preud'homme
<robotux@celest.fr> for the Debian project (and may be used by others).
This manual page was written by Thomas Preud'homme <robotux@celest.fr>,
for the Debian project (and may be used by others).

164
gcp.po Normal file
View File

@ -0,0 +1,164 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \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"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: gcp:43
msgid "Error during import"
msgstr ""
#: gcp:44
msgid "Please check dependecies:"
msgstr ""
#: gcp:50
msgid ""
"ProgressBar not available, please download it at http://pypi.python.org/pypi/"
"progressbar"
msgstr ""
#: gcp:51
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
msgid "Init DbusObject..."
msgstr ""
#: gcp:102
msgid "INTERNAL ERROR: invalid arguments"
msgstr ""
#: gcp:119
msgid "gcp launched"
msgstr ""
#: gcp:126
msgid "Init DBus..."
msgstr ""
#: gcp:155
msgid "Can't read mounts table"
msgstr ""
#: gcp:162
#, python-format
msgid "Adding to copy list: %(path)s ==> %(dest_path)s (%(fs_type)s)"
msgstr ""
#: gcp:170 gcp:192
#, python-format
msgid "Can't copy %(path)s: %(exception)s"
msgstr ""
#: gcp:179
#, python-format
msgid "Creating directory %s"
msgstr ""
#: gcp:200
#, python-format
msgid "Invalid dest_path: %s"
msgstr ""
#: gcp:205
#, python-format
msgid "The path given in arg doesn't exist or is not accessible: %s"
msgstr ""
#: gcp:210
#, python-format
msgid "omitting directory \"%s\""
msgstr ""
#: gcp:226
#, python-format
msgid "File [%s] already exists, skipping it !"
msgstr ""
#: gcp:233
#, python-format
msgid "COPYING %(source)s ==> %(dest)s"
msgstr ""
#: gcp:284
msgid "Progress: "
msgstr ""
#: gcp:315
msgid "copy directories recursively"
msgstr ""
#: gcp:318
msgid "force overwriting of existing files"
msgstr ""
#: gcp:321
msgid "preserve the specified attributes"
msgstr ""
#: gcp:324
msgid "don't fixe name encoding errors"
msgstr ""
#: gcp:327
msgid "deactivate progress bar"
msgstr ""
#: gcp:330
msgid "Show what is currently done"
msgstr ""
#: gcp:335
msgid "Progress bar is not available, deactivating"
msgstr ""
#: gcp:345
msgid ""
"Invalide --preserve value\n"
"valid values are:"
msgstr ""
#: gcp:354
#, python-format
msgid "There is already one instance of %s running, pluging to it"
msgstr ""
#: gcp:360
msgid "Wrong number of arguments"
msgstr ""
#: gcp:362
#, python-format
msgid "adding args to gcp: %s"
msgstr ""
#: gcp:373
msgid "User interruption: good bye"
msgstr ""

265
gcp.pot
View File

@ -1,265 +0,0 @@
# gcp -- translation template
#
# This file is distributed under the same license as the gcp package.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: 0.2.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-10-14 20:51+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: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: gcp:46
msgid "Error during import"
msgstr ""
#: gcp:47
msgid "Please check dependecies:"
msgstr ""
#: gcp:54
msgid "ProgressBar not available, please download it at https://pypi.org/"
msgstr ""
#: gcp:55
msgid ""
"Progress bar deactivated\n"
"--\n"
msgstr ""
#: gcp:90
msgid "Init DbusObject..."
msgstr ""
#: gcp:111
msgid "INTERNAL ERROR: invalid arguments"
msgstr ""
#: gcp:116
msgid "INTERNAL ERROR: invalid source_dir"
msgstr ""
#: gcp:171
msgid "/!\\ THE FOLLOWING FILES WERE *NOT* SUCCESSFULY COPIED:"
msgstr ""
#: gcp:177
msgid "The following files were copied, but some errors happened:"
msgstr ""
#: gcp:183
#, python-format
msgid "Please check journal: %s"
msgstr ""
#: gcp:205
msgid "gcp launched"
msgstr ""
#: gcp:213
msgid "Init DBus..."
msgstr ""
#: gcp:244
msgid "Can't read mounts table"
msgstr ""
#: gcp:251
#, python-format
msgid "Adding to copy list: %(path)s ==> %(dest_path)s (%(fs_type)s)"
msgstr ""
#: gcp:258
#, python-format
msgid "Can't copy %(path)s: %(exception)s"
msgstr ""
#: gcp:286
#, python-format
msgid "Can't append %(path)s to copy list: %(exception)s"
msgstr ""
#: gcp:289
#, python-format
msgid "Can't access %(dirpath)s: %(exception)s"
msgstr ""
#: gcp:301
#, python-format
msgid "Invalid dest_path: %s"
msgstr ""
#: gcp:306
#, python-format
msgid "The path given in arg doesn't exist or is not accessible: %s"
msgstr ""
#: gcp:310
#, python-format
msgid "omitting directory \"%s\""
msgstr ""
#: gcp:348
#, python-format
msgid "File [%s] already exists, skipping it!"
msgstr ""
#: gcp:368
#, python-format
msgid "COPYING %(source)s ==> %(dest)s"
msgstr ""
#: gcp:462
#, python-format
msgid "%.2f PiB"
msgstr ""
#: gcp:464
#, python-format
msgid "%.2f TiB"
msgstr ""
#: gcp:466
#, python-format
msgid "%.2f GiB"
msgstr ""
#: gcp:468
#, python-format
msgid "%.2f MiB"
msgstr ""
#: gcp:470
#, python-format
msgid "%.2f KiB"
msgstr ""
#: gcp:471
#, python-format
msgid "%i B"
msgstr ""
#: gcp:479 gcp:485
#, python-format
msgid "Copying %s"
msgstr ""
#: gcp:515 gcp:548
msgid ""
"No saved sources with this name, check existing names with --sources-list"
msgstr ""
#: gcp:525
msgid "Saved sources:"
msgstr ""
#: gcp:539
msgid ""
"There is already a saved sources with this name, skipping --sources-save"
msgstr ""
#: gcp:578
msgid "force overwriting of existing files"
msgstr ""
#: gcp:582
msgid "always follow symbolic links in sources"
msgstr ""
#: gcp:586
msgid "never follow symbolic links in sources"
msgstr ""
#: gcp:590
#, python-format
msgid "same as --preserve=%s"
msgstr ""
#: gcp:594
#, python-format
msgid ""
"preserve specified attributes; accepted values: 'all', or "
"one or more amongst %s"
msgstr ""
#: gcp:599
msgid "copy directories recursively"
msgstr ""
#: gcp:603
msgid "display what is being done"
msgstr ""
#: gcp:614
msgid ""
"fix file names incompatible with the destination file "
"system (default: auto)"
msgstr ""
#: gcp:619
msgid ""
"[DEPRECATED] same as --fix-filename=no (overrides --fix-"
"filenames)"
msgstr ""
#: gcp:624
msgid "disable progress bar"
msgstr ""
#: gcp:631
msgid "save sources arguments"
msgstr ""
#: gcp:635
msgid "save sources arguments and replace memory if it already exists"
msgstr ""
#: gcp:639
msgid "load sources arguments"
msgstr ""
#: gcp:643
msgid "delete saved sources list"
msgstr ""
#: gcp:647
msgid "list names of saved sources"
msgstr ""
#: gcp:651
msgid "list names of saved sources and files in it"
msgstr ""
#: gcp:663
msgid "Progress bar is not available, deactivating"
msgstr ""
#: gcp:687
#, python-format
msgid "Invalid --preserve value '%s'"
msgstr ""
#: gcp:714
#, python-format
msgid "There is already one instance of %s running, pluging to it"
msgstr ""
#: gcp:720
msgid "Wrong number of arguments"
msgstr ""
#: gcp:722
#, python-format
msgid "adding args to gcp: %s"
msgstr ""
#: gcp:731
msgid "User interruption: good bye"
msgstr ""

Binary file not shown.

View File

@ -1,50 +1,31 @@
#!/usr/bin/env python3
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import setuptools
from distribute_setup import use_setuptools
use_setuptools()
from setuptools import setup
import sys
from os import path
name = 'gcp'
setuptools.setup(
name=name,
version='0.2.1',
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',
],
scripts=['gcp'],
# entry_points={
# 'console_scripts': ['gcp=gcp:main'],
# },
data_files=[
('man/man1', ["gcp.1"]),
('share/locale/fr/LC_MESSAGES', ['i18n/fr/LC_MESSAGES/gcp.mo']),
('share/doc/%s' % name, ['CHANGELOG', 'LICENSE', 'README.md']),
],
install_requires=['PyGObject', 'dbus-python'],
python_requires='>=3',
)
setup(name=name,
version='0.1.3',
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=[(path.join(sys.prefix,'share/locale/fr/LC_MESSAGES'), ['i18n/fr/LC_MESSAGES/gcp.mo']),
('share/man/man1', ["gcp.1"]),
('share/doc/%s' % name, ['COPYING','README'])],
scripts=['gcp'],
)

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python3
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
gcp: Gcp 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,134 +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)
def test_fix_filenames(self):
"""Checks the --fix-filenames option.
"""
source = 'wi||fat<like>this:"file*name"?'
fixed_name = 'wi!!fat[like]this;\'file+name\'_'
makeRandomFile(source, S10K)
source_sha = sha1sum(source)
mkdir('dest_dir')
ret = system(GCP + " --fix-filenames=force '" + source + "' dest_dir")
self.assertNotEqual(ret, 0)
dest = join('dest_dir', fixed_name)
dest_sha = sha1sum(dest)
self.assertEqual(source_sha, dest_sha)
if __name__ == '__main__':
unittest.main()