|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
1 |
|
import argparse |
|
3
|
|
|
|
|
4
|
1 |
|
from ebook_homebrew.helper import auto |
|
5
|
1 |
|
from ebook_homebrew.helper import show_version |
|
6
|
1 |
|
from ebook_homebrew.helper import rest_api |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
1 |
|
def execute_auto(args_auto): |
|
10
|
1 |
|
auto(args_auto) |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
1 |
|
def execute_api(args_api): |
|
14
|
1 |
|
rest_api(args_api) |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
1 |
|
def main(): |
|
18
|
1 |
|
parser = argparse.ArgumentParser( |
|
19
|
|
|
prog="ebook_homebrew", |
|
20
|
|
|
usage="ebookhomebrew", |
|
21
|
|
|
description="You can make e-books for some image files", |
|
22
|
|
|
epilog="More information? Access here: https://github.com/tubone24/ebook_homebrew", |
|
23
|
|
|
add_help=True, |
|
24
|
|
|
) |
|
25
|
1 |
|
parser.add_argument("-v", "--version", action="store_true", help="Show version") |
|
26
|
|
|
|
|
27
|
1 |
|
subparsers = parser.add_subparsers( |
|
28
|
|
|
description='Choose subcommands. Usually choose "auto"' |
|
29
|
|
|
) |
|
30
|
|
|
|
|
31
|
1 |
|
parser_auto = subparsers.add_parser( |
|
32
|
|
|
"auto", |
|
33
|
|
|
description="Make only digit file name, " "convert e-book file such as PDF", |
|
34
|
|
|
help="Make only digit file name, " "convert e-book file such as PDF", |
|
35
|
|
|
) |
|
36
|
|
|
|
|
37
|
1 |
|
parser_api = subparsers.add_parser( |
|
38
|
|
|
"api", |
|
39
|
|
|
description="Run Rest API server.", |
|
40
|
|
|
help="Provides Rest API interfaces.", |
|
41
|
|
|
) |
|
42
|
|
|
|
|
43
|
1 |
|
parser_api.add_argument( |
|
44
|
|
|
"-p", |
|
45
|
|
|
"--port", |
|
46
|
|
|
action="store", |
|
47
|
|
|
nargs=1, |
|
48
|
|
|
const=None, |
|
49
|
|
|
default=None, |
|
50
|
|
|
required=True, |
|
51
|
|
|
type=int, |
|
52
|
|
|
help="API Server Port", |
|
53
|
|
|
metavar="PORT", |
|
54
|
|
|
) |
|
55
|
|
|
|
|
56
|
1 |
|
parser_auto.set_defaults(handler=execute_auto) |
|
57
|
1 |
|
parser_api.set_defaults(handler=execute_api) |
|
58
|
|
|
|
|
59
|
1 |
|
parser_auto.add_argument( |
|
60
|
|
|
"-s", |
|
61
|
|
|
"--src_dir", |
|
62
|
|
|
action="store", |
|
63
|
|
|
nargs=1, |
|
64
|
|
|
const=None, |
|
65
|
|
|
default=None, |
|
66
|
|
|
required=True, |
|
67
|
|
|
type=str, |
|
68
|
|
|
help="Source directory which put original image files.", |
|
69
|
|
|
metavar="SRC_DIR", |
|
70
|
|
|
) |
|
71
|
|
|
|
|
72
|
1 |
|
parser_auto.add_argument( |
|
73
|
|
|
"--dst_dir", |
|
74
|
|
|
action="store", |
|
75
|
|
|
nargs=1, |
|
76
|
|
|
const=None, |
|
77
|
|
|
default=None, |
|
78
|
|
|
type=str, |
|
79
|
|
|
help="Destination directory which put e-book file.", |
|
80
|
|
|
metavar="DST_DIR", |
|
81
|
|
|
) |
|
82
|
|
|
|
|
83
|
1 |
|
parser_auto.add_argument( |
|
84
|
|
|
"-d", |
|
85
|
|
|
"--digit", |
|
86
|
|
|
action="store", |
|
87
|
|
|
nargs=1, |
|
88
|
|
|
const=None, |
|
89
|
|
|
default=None, |
|
90
|
|
|
required=True, |
|
91
|
|
|
type=str, |
|
92
|
|
|
help="Serial number digits you remain file name", |
|
93
|
|
|
metavar="N,N", |
|
94
|
|
|
) |
|
95
|
|
|
|
|
96
|
1 |
|
parser_auto.add_argument( |
|
97
|
|
|
"-e", |
|
98
|
|
|
"--extension", |
|
99
|
|
|
action="store", |
|
100
|
|
|
nargs=1, |
|
101
|
|
|
const=None, |
|
102
|
|
|
default=None, |
|
103
|
|
|
required=True, |
|
104
|
|
|
type=str, |
|
105
|
|
|
help="Destination directory which put e-book file.", |
|
106
|
|
|
metavar="EXT", |
|
107
|
|
|
) |
|
108
|
|
|
|
|
109
|
1 |
|
parser_auto.add_argument( |
|
110
|
|
|
"-f", |
|
111
|
|
|
"--filename", |
|
112
|
|
|
action="store", |
|
113
|
|
|
nargs=1, |
|
114
|
|
|
const=None, |
|
115
|
|
|
default=None, |
|
116
|
|
|
required=True, |
|
117
|
|
|
type=str, |
|
118
|
|
|
help="Destination directory which put e-book file.", |
|
119
|
|
|
metavar="FILENAME", |
|
120
|
|
|
) |
|
121
|
|
|
|
|
122
|
1 |
|
parser_auto.add_argument( |
|
123
|
|
|
"-m", |
|
124
|
|
|
"--manual", |
|
125
|
|
|
action="store_true", |
|
126
|
|
|
help="Duplicate file name, solving manually.", |
|
127
|
|
|
) |
|
128
|
|
|
|
|
129
|
1 |
|
parser_auto.add_argument( |
|
130
|
|
|
"-r", "--remove", action="store_true", help="Remove original image file." |
|
131
|
|
|
) |
|
132
|
|
|
|
|
133
|
1 |
|
parser_auto.add_argument( |
|
134
|
|
|
"-y", "--assume_yes", action="store_true", help="no verify users." |
|
135
|
|
|
) |
|
136
|
|
|
|
|
137
|
1 |
|
parser_make_zip = subparsers.add_parser( |
|
138
|
|
|
"makezip", |
|
139
|
|
|
description="Make zip file for files " "which you choose extension.", |
|
140
|
|
|
help="Make zip file for adding specify extension files.", |
|
141
|
|
|
) |
|
142
|
|
|
|
|
143
|
1 |
|
parser_make_zip.add_argument( |
|
144
|
|
|
"-s", |
|
145
|
|
|
"--src_dir", |
|
146
|
|
|
action="store", |
|
147
|
|
|
nargs=1, |
|
148
|
|
|
const=None, |
|
149
|
|
|
default=None, |
|
150
|
|
|
required=True, |
|
151
|
|
|
type=str, |
|
152
|
|
|
help="Source directory which put original image files.", |
|
153
|
|
|
metavar="SRC_DIR", |
|
154
|
|
|
) |
|
155
|
|
|
|
|
156
|
1 |
|
parser_make_zip.add_argument( |
|
157
|
|
|
"--dst_dir", |
|
158
|
|
|
action="store", |
|
159
|
|
|
nargs=1, |
|
160
|
|
|
const=None, |
|
161
|
|
|
default=None, |
|
162
|
|
|
type=str, |
|
163
|
|
|
help="Destination directory which put e-book file.", |
|
164
|
|
|
metavar="DST_DIR", |
|
165
|
|
|
) |
|
166
|
|
|
|
|
167
|
1 |
|
parser_make_zip.add_argument( |
|
168
|
|
|
"-e", |
|
169
|
|
|
"--extension", |
|
170
|
|
|
action="store", |
|
171
|
|
|
nargs=1, |
|
172
|
|
|
const=None, |
|
173
|
|
|
default=None, |
|
174
|
|
|
required=True, |
|
175
|
|
|
type=str, |
|
176
|
|
|
help="Destination directory which put e-book file.", |
|
177
|
|
|
metavar="EXT", |
|
178
|
|
|
) |
|
179
|
|
|
|
|
180
|
1 |
|
parser_make_zip.add_argument( |
|
181
|
|
|
"-f", |
|
182
|
|
|
"--filename", |
|
183
|
|
|
action="store", |
|
184
|
|
|
nargs=1, |
|
185
|
|
|
const=None, |
|
186
|
|
|
default=None, |
|
187
|
|
|
required=True, |
|
188
|
|
|
type=str, |
|
189
|
|
|
help="Destination directory which put e-book file.", |
|
190
|
|
|
metavar="FILENAME", |
|
191
|
|
|
) |
|
192
|
|
|
|
|
193
|
1 |
|
parser_make_zip.add_argument( |
|
194
|
|
|
"-r", "--remove", action="store_true", help="Remove original image file." |
|
195
|
|
|
) |
|
196
|
|
|
|
|
197
|
1 |
|
parser_make_zip.add_argument( |
|
198
|
|
|
"-y", "--assume_yes", action="store_true", help="no verify users." |
|
199
|
|
|
) |
|
200
|
|
|
|
|
201
|
1 |
|
args = parser.parse_args() |
|
202
|
|
|
|
|
203
|
1 |
|
if hasattr(args, "handler"): |
|
204
|
1 |
|
args.handler(args) |
|
205
|
|
|
elif args.version: |
|
206
|
|
|
show_version() |
|
207
|
|
|
else: |
|
208
|
|
|
parser.print_help() |
|
209
|
|
|
|
|
210
|
|
|
|
|
211
|
1 |
|
if __name__ == "__main__": |
|
212
|
|
|
main() |
|
213
|
|
|
|