manage.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. """
  2. Managing existing objects in a GRASS GIS Spatial Database
  3. (C) 2020 by the GRASS Development Team
  4. This program is free software under the GNU General Public
  5. License (>=v2). Read the file COPYING that comes with GRASS
  6. for details.
  7. .. sectionauthor:: Vaclav Petras <wenzeslaus gmail com>
  8. """
  9. import os
  10. import shutil
  11. def delete_mapset(database, location, mapset):
  12. """Deletes a specified mapset"""
  13. if mapset == "PERMANENT":
  14. raise ValueError(
  15. _("Mapset PERMANENT cannot be deleted (a whole location can be)")
  16. )
  17. shutil.rmtree(os.path.join(database, location, mapset))
  18. def delete_location(database, location):
  19. """Deletes a specified location"""
  20. shutil.rmtree(os.path.join(database, location))
  21. def delete_grassdb(database):
  22. """Deletes a specified GRASS database"""
  23. shutil.rmtree(database)
  24. def rename_mapset(database, location, old_name, new_name):
  25. """Rename mapset from *old_name* to *new_name*"""
  26. if old_name == "PERMANENT":
  27. raise ValueError(_("Mapset PERMANENT cannot be renamed"))
  28. location_path = os.path.join(database, location)
  29. os.rename(
  30. os.path.join(location_path, old_name), os.path.join(location_path, new_name)
  31. )
  32. def rename_location(database, old_name, new_name):
  33. """Rename location from *old_name* to *new_name*"""
  34. os.rename(os.path.join(database, old_name), os.path.join(database, new_name))
  35. def split_mapset_path(mapset_path):
  36. """Split mapset path to three parts - grassdb, location, mapset"""
  37. path, mapset = os.path.split(mapset_path.rstrip(os.sep))
  38. grassdb, location = os.path.split(path)
  39. return grassdb, location, mapset