t.info.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ############################################################################
  4. #
  5. # MODULE: t.info
  6. # AUTHOR(S): Soeren Gebbert
  7. #
  8. # PURPOSE: Print information about a space-time dataset
  9. # COPYRIGHT: (C) 2011-2017 by the GRASS Development Team
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. #
  21. #############################################################################
  22. #%module
  23. #% description: Lists information about space time datasets and maps.
  24. #% keyword: temporal
  25. #% keyword: metadata
  26. #% keyword: extent
  27. #% keyword: time
  28. #%end
  29. #%option G_OPT_STDS_INPUT
  30. #% description: Name of an existing space time dataset or map
  31. #%end
  32. #%option G_OPT_STDS_TYPE
  33. #% guidependency: input
  34. #% guisection: Required
  35. #% options: strds, str3ds, stvds, raster, raster_3d, vector
  36. #%end
  37. #%flag
  38. #% key: g
  39. #% description: Print in shell script style
  40. #%end
  41. #%flag
  42. #% key: h
  43. #% description: Print history information in human readable shell style for space time datasets
  44. #%end
  45. #%flag
  46. #% key: d
  47. #% description: Print information about the temporal DBMI interface and exit
  48. #% suppress_required: yes
  49. #%end
  50. from __future__ import print_function
  51. import grass.script as grass
  52. ############################################################################
  53. def main():
  54. # lazy imports
  55. import grass.temporal as tgis
  56. name = options["input"]
  57. type_ = options["type"]
  58. shellstyle = flags['g']
  59. system = flags['d']
  60. history = flags['h']
  61. # Make sure the temporal database exists
  62. tgis.init()
  63. dbif, connected = tgis.init_dbif(None)
  64. rows = tgis.get_tgis_metadata(dbif)
  65. if system and not shellstyle and not history:
  66. # 0123456789012345678901234567890
  67. print(" +------------------- Temporal DBMI backend information ----------------------+")
  68. print(" | DBMI Python interface:...... " + str(dbif.get_dbmi().__name__))
  69. print(" | Temporal database string:... " + str(
  70. tgis.get_tgis_database_string()))
  71. print(" | SQL template path:.......... " + str(
  72. tgis.get_sql_template_path()))
  73. if rows:
  74. for row in rows:
  75. print(" | %s .......... %s"%(row[0], row[1]))
  76. print(" +----------------------------------------------------------------------------+")
  77. return
  78. elif system and not history:
  79. print("dbmi_python_interface=\'" + str(dbif.get_dbmi().__name__) + "\'")
  80. print("dbmi_string=\'" + str(tgis.get_tgis_database_string()) + "\'")
  81. print("sql_template_path=\'" + str(tgis.get_sql_template_path()) + "\'")
  82. if rows:
  83. for row in rows:
  84. print("%s=\'%s\'"%(row[0], row[1]))
  85. return
  86. if not system and not name:
  87. grass.fatal(_("Please specify %s=") % ("name"))
  88. if name.find("@") >= 0:
  89. id_ = name
  90. else:
  91. id_ = name + "@" + grass.gisenv()["MAPSET"]
  92. dataset = tgis.dataset_factory(type_, id_)
  93. if dataset.is_in_db(dbif) == False:
  94. grass.fatal(_("Dataset <%s> not found in temporal database") % (id_))
  95. dataset.select(dbif)
  96. if history == True and type_ in ["strds", "stvds", "str3ds"]:
  97. dataset.print_history()
  98. return
  99. if shellstyle == True:
  100. dataset.print_shell_info()
  101. else:
  102. dataset.print_info()
  103. if __name__ == "__main__":
  104. options, flags = grass.parser()
  105. main()