manage.py 1.4 KB

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