-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio.py
More file actions
60 lines (42 loc) · 1 KB
/
Copy pathio.py
File metadata and controls
60 lines (42 loc) · 1 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
from kamidana import (
as_filter,
)
from jinja2 import pass_context
import io
import os
import sys
# no univeral newlines
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, newline='')
@as_filter
@pass_context
def relativepath(ctx, v):
dirname = os.path.dirname(os.path.abspath(ctx.name))
return os.path.normpath(os.path.join(dirname, v))
@as_filter
@pass_context
def abspath(ctx, v):
return os.path.abspath(str(v))
@as_filter
@pass_context
def basename(ctx, v):
return os.path.basename(str(v))
@as_filter
@pass_context
def dirname(ctx, v):
return os.path.dirname(str(v))
@as_filter
@pass_context
def path_exists(ctx, v):
return os.path.exists(str(v))
@as_filter
@pass_context
def listdir(ctx, v):
return os.listdir(str(v))
@as_filter
@pass_context
def listdir_files(ctx, v):
return [f for f in os.listdir(str(v)) if os.path.isfile(os.path.join(str(v), f))]
@as_filter
@pass_context
def listdir_dirs(ctx, v):
return [f for f in os.listdir(str(v)) if os.path.isdir(os.path.join(str(v), f))]