-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfileutils.py
More file actions
64 lines (55 loc) · 1.54 KB
/
fileutils.py
File metadata and controls
64 lines (55 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
""" File utilities module
-----------------------------------
| Copyright 2022 by Joel C. Alcarez |
| [[email protected]] |
|-----------------------------------|
| We make absolutely no warranty |
| of any kind, expressed or implied |
|-----------------------------------|
| The primary author and any |
| any subsequent code contributors |
| shall not be liable in any event |
| for incidental or consequential |
| damages in connection with, or |
| arising out from the use of this |
| code in current form or with any |
| modifications. |
-----------------------------------
"""
from os.path import isfile
from typing import Callable
from .messages import sysmsg
from functools import wraps
def checklink(func: Callable):
"""Decorator to test if the first
parameter in a function is
a valid file
Args:
function
Returns:
caller function
"""
@wraps(func)
def callf(*args, **kwargs):
if isfile(args[0]):
return(func(*args, **kwargs))
else:
print(sysmsg['filenotexist'])
return(callf)
def checklinks(func: Callable):
"""Decorator to test if the two
parameters in a function
are valid files
Args:
function
Returns:
caller function
"""
@wraps(func)
def callf(*args, **kwargs):
if isfile(args[0]) and \
isfile(args[1]):
return(func(*args, **kwargs))
else:
print(sysmsg['filenotexist'])
return(callf)