Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Medizinische Informatik - Öffentliche Projekte
UMG MeDIC
MeDIC Technik
AW Agents
File Mover
Commits
ea7af2e2
Commit
ea7af2e2
authored
Feb 17, 2022
by
brandt73
Browse files
Merge branch 'rbrandt-implement-file-mask' into 'master'
implements file mask selection argument See merge request
!13
parents
5dca40c9
57dabedb
Pipeline
#276059
passed with stages
in 13 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
ea7af2e2
...
...
@@ -14,7 +14,15 @@ _Types of changes_:
*
`Fixed`
for any bug fixes.
*
`Security`
in case of vulnerabilities.
## [Unreleased]
## [Released]
## [0.8.3] - 2022-02-16
### Added
-
Introduced new
`file_mask`
option to limit the files to process. This is a string value which is used
in a
`glob.glob()`
call to select only files matching the selected criteria. Example:
`"file_mask": "*.csv"`
will only process files with the
`.csv`
extension.
## [0.8.2] - 2022-02-16
...
...
README.md
View file @
ea7af2e2
...
...
@@ -24,6 +24,8 @@ as an option with all incoming `check` and `receive` requests. See agent
[
usage description
](
mover/description.md#Options
)
for details.
*
`default_destination_dir`
: Default target directory for copy or move operations. See agent
[
usage description
](
mover/description.md#Options
)
for details.
*
`file_mask`
: Limits the selection of files to a specified file mask. See agent
[
usage description
](
mover/description.md#Options
)
for details.
## Usage
...
...
mover/__version__.py
View file @
ea7af2e2
VERSION
=
(
0
,
8
,
2
)
VERSION
=
(
0
,
8
,
3
)
__version__
=
"."
.
join
(
map
(
str
,
VERSION
))
...
...
mover/description.md
View file @
ea7af2e2
...
...
@@ -42,6 +42,8 @@ successfully moved files from the source path.
function that will be supplied as a
`key`
to
`sorted()`
. Example:
`lambda file: os.path.getmtime(file)`
sorts files by last modification.
*
`order_reverse`
: Boolean, reverses the order from
`order`
if set to "true".
*
`file_mask:`
option to limit the files to process. This is a string value which is used
in a
`glob.glob()`
call to select only files matching the selected criteria.
### Full Example
...
...
@@ -55,7 +57,8 @@ successfully moved files from the source path.
"modified": "not today",
"limit": 10,
"order": "sorted",
"order_reverse": "false"
"order_reverse": "false",
"file_mask": "*.csv"
}
}
```
mover/mover.py
View file @
ea7af2e2
import
glob
import
logging
import
os
import
shutil
...
...
@@ -26,6 +27,7 @@ def move(
order
=
None
order_reverse
=
False
limit
=
0
file_mask
=
None
if
len
(
criteria
):
keys
=
criteria
.
keys
()
...
...
@@ -42,6 +44,8 @@ def move(
limit
=
int
(
criteria
[
"limit"
])
if
"order"
in
keys
:
order
=
criteria
[
"order"
]
if
"file_mask"
in
keys
:
file_mask
=
criteria
[
"file_mask"
]
if
"order_reverse"
in
keys
:
if
type
(
criteria
[
"order_reverse"
])
is
bool
:
order_reverse
=
criteria
[
"order_reverse"
]
...
...
@@ -55,7 +59,13 @@ def move(
order_reverse
=
criteria
[
"order_reverse"
]
>
0
try
:
source_files
=
os
.
listdir
(
source
)
if
file_mask
:
if
source
[
-
1
]
!=
"/"
:
source
=
source
+
"/"
source_files
=
[
os
.
path
.
basename
(
x
)
for
x
in
glob
.
glob
(
source
+
file_mask
)]
else
:
source_files
=
os
.
listdir
(
source
)
if
order
:
# use special keyword "sorted" for simple sorting
if
order
==
"sorted"
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment