home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 June / CHIP 2006-06.2.iso / program / freeware / Democracy-0.8.2.exe / xulrunner / python / BitTorrent / __init__.py next >
Encoding:
Python Source  |  2006-04-10  |  3.1 KB  |  99 lines

  1. # The contents of this file are subject to the BitTorrent Open Source License
  2. # Version 1.0 (the License).  You may not copy or use this file, in either
  3. # source code or executable form, except in compliance with the License.  You
  4. # may obtain a copy of the License at http://www.bittorrent.com/license/.
  5. #
  6. # Software distributed under the License is distributed on an AS IS basis,
  7. # WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
  8. # for the specific language governing rights and limitations under the
  9. # License.
  10.  
  11. app_name = "BitTorrent"
  12. version = '4.0.0'
  13.  
  14. URL = 'http://www.bittorrent.com/'
  15. DONATE_URL = URL + 'donate.html'
  16. FAQ_URL = URL + 'FAQ.html'
  17. HELP_URL = URL + 'documentation.html'
  18.  
  19. import sys
  20. assert sys.version_info >= (2, 2, 1), "Python 2.2.1 or newer required"
  21. import os
  22.  
  23. def calc_unix_dirs():
  24.     appdir = '%s-%s'%(app_name, version)
  25.     ip = os.path.join('share', 'pixmaps', appdir)
  26.     dp = os.path.join('share', 'doc'    , appdir)
  27.     return ip, dp
  28.  
  29. # GRS 11/06/05: When embedding Python, sometimes there is no sys.argv.
  30. # Fortunately sys.argv is used only to calculate image_root and
  31. # doc_root; the former is used only in Bittorrent's GUI.py, and the
  32. # latter is not used at all.
  33. #app_root = os.path.split(os.path.abspath(sys.argv[0]))[0]
  34. app_root = ""
  35. image_root = os.path.join(app_root, 'images')
  36. doc_root = app_root
  37.  
  38. if app_root.startswith(os.path.join(sys.prefix,'bin')):
  39.     # I'm installed on *nix
  40.     image_root, doc_root = map( lambda p: os.path.join(sys.prefix, p), calc_unix_dirs() )
  41.  
  42.  
  43. # a cross-platform way to get user's home directory
  44. def get_config_dir():
  45.     shellvars = ['${APPDATA}', '${HOME}', '${USERPROFILE}']
  46.     return get_dir_root(shellvars)
  47.  
  48. def get_home_dir():
  49.     shellvars = ['${HOME}', '${USERPROFILE}']
  50.     return get_dir_root(shellvars)
  51.  
  52. def get_dir_root(shellvars):
  53.     def check_sysvars(x):
  54.         y = os.path.expanduser(os.path.expandvars(x))
  55.         if y != x and os.path.isdir(y):
  56.             return y
  57.         return None
  58.  
  59.     dir_root = None
  60.     for d in shellvars:
  61.         dir_root = check_sysvars(d)
  62.         if dir_root is not None:
  63.             break
  64.     else:
  65.         dir_root = os.path.expanduser('~')
  66.         if dir_root == '~' or not os.path.isdir(dir_root):
  67.             dir_root = None
  68.     return dir_root
  69.  
  70.  
  71. is_frozen_exe = (os.name == 'nt') and hasattr(sys, 'frozen') and (sys.frozen == 'windows_exe')
  72.  
  73. # hackery to get around bug in py2exe that tries to write log files to
  74. # application directories, which may not be writable by non-admin users
  75. if is_frozen_exe:
  76.     baseclass = sys.stderr.__class__
  77.     class Stderr(baseclass):
  78.         logroot = get_home_dir()
  79.         if logroot is None:
  80.             logroot = os.path.splitdrive(sys.executable)[0]
  81.         logname = os.path.splitext(os.path.split(sys.executable)[1])[0] + '_errors.log'
  82.         logpath = os.path.join(logroot, logname)
  83.         def write(self, text, alert=None, fname=logpath):
  84.             baseclass.write(self, text, fname=fname)
  85.     sys.stderr = Stderr()
  86.  
  87. del sys
  88.  
  89. INFO = 0
  90. WARNING = 1
  91. ERROR = 2
  92. CRITICAL = 3
  93.  
  94. class BTFailure(Exception):
  95.     pass
  96.  
  97. class BTShutdown(BTFailure):
  98.     pass
  99.