This repository has been archived by the owner on Jul 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
lfp-picture.py
executable file
·132 lines (107 loc) · 3.63 KB
/
lfp-picture.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python
#
# lfp-reader
# LFP (Light Field Photography) File Reader.
#
# http://code.behnam.es/python-lfp-reader/
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2012-2013 Behnam Esfahbod
"""Parse LFP Picture files and access embedded data
"""
from __future__ import print_function
import os.path
import sys
import argparse
from lfp_reader import LfpPictureFile, lfp_logging
lfp_logging.set_log_stream(sys.stdout)
DEBUG = False
QUIET = False
def info(lfp_files, **null):
"""Show information about LFP Picture file
"""
for idx, lfp_file in enumerate(lfp_files):
if not QUIET:
if idx > 0: print()
print("LFP Picture file: %s" % lfp_file.name)
LfpPictureFile(lfp_file).load().print_info()
def export(lfp_files, **null):
"""Export LFP Picture file into separate data files
"""
for idx, lfp_file in enumerate(lfp_files):
if not QUIET:
if idx > 0: print()
print("LFP Picture file: %s" % lfp_file.name)
LfpPictureFile(lfp_file).load().export()
def main(argv=sys.argv[1:]):
"""Parse command-line arguments and call commands
"""
global DEBUG, QUIET
debug_kwargs = dict(
action='store_true',
help="Print debugging information on error",
)
quiet_kwargs = dict(
action='store_true',
help="Do not write anything to standard output",
)
lfp_file_kwargs = dict(
type=argparse.FileType(mode='rb'),
metavar='picture.lfp',
help='LFP Picture file path ("IMG_0001.lfp")',
)
# Main command
p_main = argparse.ArgumentParser(description=__doc__)
p_subs = p_main.add_subparsers(title='subcommands')
# Info command
p_info = p_subs.add_parser('info', help=info.__doc__)
p_info.set_defaults(subcmd=info)
p_info.add_argument('-d', '--debug', **debug_kwargs)
p_info.add_argument('-q', '--quiet', **quiet_kwargs)
p_info.add_argument('lfp_files', nargs='+', **lfp_file_kwargs)
# Export command
p_export = p_subs.add_parser('export', help=export.__doc__)
p_export.set_defaults(subcmd=export)
p_export.add_argument('-d', '--debug', **debug_kwargs)
p_export.add_argument('-q', '--quiet', **quiet_kwargs)
p_export.add_argument('lfp_files', nargs='+', **lfp_file_kwargs)
# Parse arguments
try:
args = p_main.parse_args(argv)
except SystemExit:
print()
if 'info' in argv:
p_info.print_help()
elif 'export' in argv:
p_export.print_help()
else:
p_main.print_help()
sys.exit(2)
# Run subcommand
DEBUG = args.debug
QUIET = args.quiet
args.subcmd(**dict(args._get_kwargs()))
if __name__=='__main__':
try:
main()
except KeyboardInterrupt:
sys.exit(3)
except Exception as err:
if DEBUG:
raise
else:
if not QUIET:
print("%s: error: %s" % (os.path.basename(sys.argv[0]), err), file=sys.stderr)
sys.exit(9)