manage.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 rename_mapset(database, location, old_name, new_name):
  22. """Rename mapset from *old_name* to *new_name*"""
  23. if old_name == "PERMANENT":
  24. raise ValueError(_("Mapset PERMANENT cannot be renamed"))
  25. location_path = os.path.join(database, location)
  26. os.rename(
  27. os.path.join(location_path, old_name), os.path.join(location_path, new_name)
  28. )
  29. def rename_location(database, old_name, new_name):
  30. """Rename location from *old_name* to *new_name*"""
  31. os.rename(os.path.join(database, old_name), os.path.join(database, new_name))