1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6import sys
7import logging
9logger = logging.getLogger('main')
12def main():
13 logging.basicConfig(
14 level=logging.INFO,
15 format='pyrocko:%(name)-25s - %(levelname)-8s - %(message)s')
17 try:
18 from pyrocko import squirrel
20 class PrintVersion(squirrel.SquirrelCommand):
21 def make_subparser(self, subparsers):
22 return subparsers.add_parser(
23 'version', help='Print version.')
25 def setup(self, parser):
26 parser.add_argument(
27 '--long',
28 dest='long',
29 action='store_true',
30 help='Print long version string.')
32 def run(self, parser, args):
33 import pyrocko
34 if args.long:
35 print(pyrocko.long_version)
36 else:
37 print(pyrocko.__version__)
39 class PrintDependencies(squirrel.SquirrelCommand):
40 def make_subparser(self, subparsers):
41 return subparsers.add_parser(
42 'dependencies',
43 help='Print versions of available dependencies.')
45 def setup(self, parser):
46 pass
48 def run(self, parser, args):
49 from pyrocko import deps
50 deps.print_dependencies()
52 class PrintInfo(squirrel.SquirrelCommand):
53 def make_subparser(self, subparsers):
54 return subparsers.add_parser(
55 'info',
56 help='Print information about Pyrocko installation(s).')
58 def setup(self, parser):
59 pass
61 def run(self, parser, args):
62 from pyrocko import deps
63 print()
64 print('Python executable:\n %s' % sys.executable)
65 print()
66 deps.print_installations()
68 squirrel.run(
69 subcommands=[
70 PrintVersion(),
71 PrintDependencies(),
72 PrintInfo()],
73 description='Tools for seismology.')
75 except ImportError as e:
76 from pyrocko import deps
77 logger.info('\n' + deps.str_dependencies())
78 logger.info('\n' + deps.str_installations())
80 try:
81 deps.require_all('required')
83 except deps.MissingPyrockoDependency as e2:
84 logger.fatal(str(e2))
85 sys.exit(1)
87 logger.fatal(str(e))
88 sys.exit(1)
91if __name__ == '__main__':
92 main()