/src/paths.py

https://code.google.com/p/sugar-clic/ · Python · 104 lines · 48 code · 21 blank · 35 comment · 4 complexity · b43b0df15664f0aa71ea9018493f1617 MD5 · raw file

  1. '''
  2. This file is part of Sugar-Clic
  3. Sugar-Clic is copyrigth 2009 by Maria Jose Casany Guerrero and Marc Alier Forment
  4. of the Universitat Politecnica de Catalunya http://www.upc.edu
  5. Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier
  6. @ upc.edu
  7. Sugar-Clic is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11. Sugar-Clic is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with Sugar-Clic. If not, see <http://www.gnu.org/licenses/>.
  17. @package sugarclic
  18. @copyrigth 2009 Marc Alier, Maria Jose Casany marc.alier@upc.edu
  19. @copyrigth 2009 Universitat Politecnica de Catalunya http://www.upc.edu
  20. @autor Marc Alier
  21. @autor Jordi Piguillem
  22. @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. '''
  24. from sugar.activity import activity
  25. import os
  26. # paths used in the application
  27. application_data_path = '' #path where the application can store permanent data
  28. application_bundle_path = '' #path where the application is installed (/home/olpc/Activities/ClicPlayer.activity
  29. clics_path = '' #path to the folder that contains default clics
  30. new_clics_path = '' #path to the folder that contains new clics
  31. about_path = '' #path to the folder that contains the about info
  32. manual_path = '' #path to the folder that contains the manual
  33. db_downloaded = '' #path to db of new clics
  34. db_default = '' #path to db of default clics
  35. icons_path = '' #path to the icons used in the application (clics icon, button icons,...)
  36. views_path = '' #path to the views of the application
  37. #Returns the absolute path of the clic folder
  38. def get_clic_path(clic_name, is_default):
  39. p = new_clics_path
  40. if is_default == '1':
  41. p = application_bundle_path + '/data/clics'
  42. return os.path.join(p , clic_name)
  43. def set_environment(is_Xo):
  44. global application_bundle_path, application_data_path, clics_path, about_path, manual_path, new_clics_path, db_downloaded, db_default, icons_path, views_path
  45. if is_Xo : #Sets environment for a XO-laptop.
  46. application_data_path = os.path.join(activity.get_activity_root(), 'data')
  47. application_bundle_path = activity.get_bundle_path()
  48. clics_path = os.path.join(application_bundle_path , 'data/clics')
  49. new_clics_path = application_data_path + '/clics'
  50. about_path = application_bundle_path + '/data/clics/about'
  51. manual_path = application_bundle_path + '/data/clics/sugar_clic_help'
  52. db_downloaded = os.path.join(application_data_path , 'downloaded.xml')
  53. db_default = os.path.join(application_bundle_path , 'data/default.xml')
  54. img_app_path = os.path.join(application_bundle_path, 'img/app')
  55. views_path = os.path.join(img_app_path, 'appViews')
  56. icons_path = os.path.join(img_app_path, 'appIcons')
  57. else: #Sets environment for a UNIX computer.
  58. current_path = os.getcwd()
  59. application_data_path = os.path.join(current_path, 'new/data')
  60. application_bundle_path = current_path
  61. clics_path = os.path.join(application_bundle_path , 'data/clics')
  62. new_clics_path = application_data_path + '/clics'
  63. about_path = application_bundle_path + '/data/clics/about'
  64. manual_path = application_bundle_path + '/data/clics/sugar_clic_help'
  65. db_downloaded = os.path.join(application_data_path , 'downloaded.xml')
  66. db_default = os.path.join(application_bundle_path , 'data/default.xml')
  67. img_app_path = os.path.join(application_bundle_path, 'img/app')
  68. views_path = os.path.join(img_app_path, 'appViews')
  69. icons_path = os.path.join(img_app_path, 'appIcons')
  70. __create_clics_path()
  71. #creates the folder that will contain the new clics (downloaded or installed from usb)
  72. def __create_clics_path():
  73. if not os.path.exists(new_clics_path):
  74. t = os.system('mkdir ' + new_clics_path)