1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

4# ---|P------/S----------~Lg---------- 

5 

6import sys 

7import logging 

8 

9logger = logging.getLogger('main') 

10 

11 

12def main(): 

13 logging.basicConfig( 

14 level=logging.INFO, 

15 format='pyrocko:%(name)-25s - %(levelname)-8s - %(message)s') 

16 

17 try: 

18 from pyrocko import squirrel 

19 

20 class PrintVersion(squirrel.SquirrelCommand): 

21 def make_subparser(self, subparsers): 

22 return subparsers.add_parser( 

23 'version', help='Print version.') 

24 

25 def setup(self, parser): 

26 parser.add_argument( 

27 '--long', 

28 dest='long', 

29 action='store_true', 

30 help='Print long version string.') 

31 

32 def run(self, parser, args): 

33 import pyrocko 

34 if args.long: 

35 print(pyrocko.long_version) 

36 else: 

37 print(pyrocko.__version__) 

38 

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.') 

44 

45 def setup(self, parser): 

46 pass 

47 

48 def run(self, parser, args): 

49 from pyrocko import deps 

50 deps.print_dependencies() 

51 

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).') 

57 

58 def setup(self, parser): 

59 pass 

60 

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() 

67 

68 squirrel.run( 

69 subcommands=[ 

70 PrintVersion(), 

71 PrintDependencies(), 

72 PrintInfo()], 

73 description='Tools for seismology.') 

74 

75 except ImportError as e: 

76 from pyrocko import deps 

77 logger.info('\n' + deps.str_dependencies()) 

78 logger.info('\n' + deps.str_installations()) 

79 

80 try: 

81 deps.require_all('required') 

82 

83 except deps.MissingPyrockoDependency as e2: 

84 logger.fatal(str(e2)) 

85 sys.exit(1) 

86 

87 logger.fatal(str(e)) 

88 sys.exit(1) 

89 

90 

91if __name__ == '__main__': 

92 main()