mirror of
https://github.com/arsenetar/dupeguru.git
synced 2026-01-22 14:41:39 +00:00
Reorganized hscommon documentation
Removed hscommon's "docs" folder and moved all documentation directly into docstrings. Then, in dupeGuru's developer documentation, added autodoc references to relevant modules. The result is a much more usable hscommon documentation.
This commit is contained in:
@@ -6,6 +6,10 @@
|
||||
# which should be included with this package. The terms are also available at
|
||||
# http://www.hardcoded.net/licenses/bsd_license
|
||||
|
||||
"""When you have to deal with names that have to be unique and can conflict together, you can use
|
||||
this module that deals with conflicts by prepending unique numbers in ``[]`` brackets to the name.
|
||||
"""
|
||||
|
||||
import re
|
||||
import os
|
||||
import shutil
|
||||
@@ -18,7 +22,7 @@ from .path import Path, pathify
|
||||
re_conflict = re.compile(r'^\[\d{3}\d*\] ')
|
||||
|
||||
def get_conflicted_name(other_names, name):
|
||||
"""Returns name with a [000] number in front of it.
|
||||
"""Returns name with a ``[000]`` number in front of it.
|
||||
|
||||
The number between brackets depends on how many conlicted filenames
|
||||
there already are in other_names.
|
||||
@@ -34,16 +38,21 @@ def get_conflicted_name(other_names, name):
|
||||
i += 1
|
||||
|
||||
def get_unconflicted_name(name):
|
||||
"""Returns ``name`` without ``[]`` brackets.
|
||||
|
||||
Brackets which, of course, might have been added by func:`get_conflicted_name`.
|
||||
"""
|
||||
return re_conflict.sub('',name,1)
|
||||
|
||||
def is_conflicted(name):
|
||||
"""Returns whether ``name`` is prepended with a bracketed number.
|
||||
"""
|
||||
return re_conflict.match(name) is not None
|
||||
|
||||
@pathify
|
||||
def _smart_move_or_copy(operation, source_path: Path, dest_path: Path):
|
||||
''' Use move() or copy() to move and copy file with the conflict management, but without the
|
||||
slowness of the fs system.
|
||||
'''
|
||||
"""Use move() or copy() to move and copy file with the conflict management.
|
||||
"""
|
||||
if dest_path.isdir() and not source_path.isdir():
|
||||
dest_path = dest_path[source_path.name]
|
||||
if dest_path.exists():
|
||||
@@ -54,9 +63,13 @@ def _smart_move_or_copy(operation, source_path: Path, dest_path: Path):
|
||||
operation(str(source_path), str(dest_path))
|
||||
|
||||
def smart_move(source_path, dest_path):
|
||||
"""Same as :func:`smart_copy`, but it moves files instead.
|
||||
"""
|
||||
_smart_move_or_copy(shutil.move, source_path, dest_path)
|
||||
|
||||
def smart_copy(source_path, dest_path):
|
||||
"""Copies ``source_path`` to ``dest_path``, recursively and with conflict resolution.
|
||||
"""
|
||||
try:
|
||||
_smart_move_or_copy(shutil.copy, source_path, dest_path)
|
||||
except IOError as e:
|
||||
|
||||
Reference in New Issue
Block a user