logger.trace('The following files have been filtered out from download candidates due to include / exclude rules:\n'+str(filtered_files))# type: ignore[attr-defined]
logger.trace('The following files are left as download candidates after filtering with include / exclude rules:\n'+str([f.pathforfinremote_files_filtered]))# type: ignore[attr-defined]
logger.debug(f"[to download] Remote file {f.path} does not exist locally as {local_path}. Will be downloaded.")# pylint: disable=logging-fstring-interpolation
# copy
to_download.append(rel_path)
continue
ifnotos.path.isfile(local_path):
ifis_ignored(remote_path):
logger.trace(f"[ignore] Local non-regular file {local_path} is left as it is since it is ignored. Would be deleted and re-downloaded otherwise")# type: ignore[attr-defined]
continue
logger.debug(f"Local path {local_path} is not a regular file, but remote path {f.path} is a regular file. Will be deleted and re-downloaded.")# pylint: disable=logging-fstring-interpolation
logger.trace(f"[ignore] Local file {local_path} is left as it is since it is ignored. Would be overridden otherwise, since remote file {f.path} is {td_str} than local file.")# type: ignore[attr-defined]
continue
logger.debug(f"[to download] Remote file {f.path} is {td_str} than local file {local_path}. Will be re-downloaded.")# pylint: disable=logging-fstring-interpolation
# copy
to_download.append(rel_path)
continue
else:
logger.trace(f"[no action] Local file {local_path} exists with same timestamp in remote. Nothing to do.")# type: ignore[attr-defined]
logger.error('Got HTTP error 401, which means "Unauthorized". Can be caused by a wrong owncloud password or link or the link is not publicly shared.')
else:
logger.error('Got HTTP error: %s',e)
return1
exceptrequests.ConnectionErrorase:
logger.error('Got a connection error. Maybe you got the URL wrong. Full error msg: %s',e)
return1
finally:
oc.logout()
return0
defparse_args(argv:Sequence[str]):
parser=argparse.ArgumentParser(
description='Download files from a public owncloud link share to a local target directory. Existing files will be re-downloaded, if the modified date of the files differ. You can select which upstream files to consider using --include and --exclude and you can leave existing local files using --ignore.',
Files matching the glob-pattern will be included or excluded, respectively. Paths can start with / for the root of the shared directory. Can be used multiple times and the order matters. If --include is not used before --exclude, all files will be included. You can e. g. exclude all *.txt files and include a specific *.txt file again:
--exclude='*.txt' --include='/include_me.txt'
But if you do it the other way round, no file will be left, since at first only /include_me.txt will be included and then all *.txt files will be excluded:
--include='/include_me.txt' --exclude='*.txt'
Note: * matches also / in the path.
Note: Protect * using single-quotes around the argument.
Note: include/exclude patterns are applied to the remote files only. Local files are not filtered by these patterns. This also means excluded files will be deleted locally if they are not ignored by --ignore. If you want to exclude files from being overriden or deleted, use --ignore instead.'''))
inex_group.add_argument('--include',action=OrderedArgs,dest='inex',help="Include file pattern. Example: --include='/*.txt' will match all *.txt files in all subdirectories. If this is used as only include/exclude option, all other files will be excluded.")
inex_group.add_argument('--exclude',action=OrderedArgs,dest='inex',help="Exclude file pattern. Example: --exclude='?*/*.txt' will exclude *.txt files in subdirectories, but keep *.txt files in the share's root directory.")
parser.add_argument('--ignore',action='append',default=[],dest='ignores',help="Glob-pattern to ignore local files. Can be used multiple times. Matching existing files will not be deleted or overridden. However, they will still be downloaded, if they are not present locally. This is useful for files that are not in the remote share (anymore), but you want to keep them locally or for files that you have updated locally. Example: --ignore='*augmented/*' will keep the temporary files in any directory ending with 'augmented'.")
parser.add_argument('--password',default='',help='In case the public owncloud share link requires a password, provide it with this argument.')