/BitTorrent/__init__.py

https://github.com/mbologna/BitFountain · Python · 88 lines · 56 code · 20 blank · 12 comment · 11 complexity · 33147e2858e40f38489716e19464c67d MD5 · raw file

  1. # -*- coding: UTF-8 -*-
  2. # The contents of this file are subject to the BitTorrent Open Source License
  3. # Version 1.1 (the License). You may not copy or use this file, in either
  4. # source code or executable form, except in compliance with the License. You
  5. # may obtain a copy of the License at http://www.bittorrent.com/license/.
  6. #
  7. # Software distributed under the License is distributed on an AS IS basis,
  8. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  9. # for the specific language governing rights and limitations under the
  10. # License.
  11. app_name = 'BitFountain'
  12. version = '2.0.0'
  13. URL = 'http://www.bittorrent.com/'
  14. DONATE_URL = URL + 'donate.html'
  15. FAQ_URL = URL + 'FAQ.html'
  16. HELP_URL = URL + 'documentation.html'
  17. SEARCH_URL = 'http://search.bittorrent.com/search.jsp?client=%(client)s&query=%(query)s'
  18. import sys
  19. assert sys.version_info >= (2, 2, 1), _("Python %s or newer required") % '2.2.1'
  20. import os
  21. import time
  22. branch = None
  23. if os.access('.cdv', os.F_OK):
  24. branch = os.path.split(os.path.realpath(os.path.split(sys.argv[0])[0]))[1]
  25. from BitTorrent.language import languages, language_names
  26. from BitTorrent.platform import get_home_dir, is_frozen_exe
  27. if os.name == 'posix':
  28. if os.uname()[0] == "Darwin":
  29. from BitTorrent.platform import install_translation
  30. install_translation()
  31. # hackery to get around bug in py2exe that tries to write log files to
  32. # application directories, which may not be writable by non-admin users
  33. if is_frozen_exe:
  34. baseclass = sys.stderr.__class__
  35. class Stderr(baseclass):
  36. logroot = get_home_dir()
  37. if logroot is None:
  38. logroot = os.path.splitdrive(sys.executable)[0]
  39. if logroot[-1] != os.sep:
  40. logroot += os.sep
  41. logname = os.path.splitext(os.path.split(sys.executable)[1])[0] + '_errors.log'
  42. logpath = os.path.join(logroot, logname)
  43. def __init__(self):
  44. self.just_wrote_newline = True
  45. def write(self, text, alert=None, fname=logpath):
  46. output = text
  47. if self.just_wrote_newline and not text.startswith('[%s ' % version):
  48. output = '[%s %s] %s' % (version, time.strftime('%Y-%m-%d %H:%M:%S'), text)
  49. if 'GtkWarning' not in text:
  50. baseclass.write(self, output, fname=fname)
  51. if output[-1] == '\n':
  52. self.just_wrote_newline = True
  53. else:
  54. self.just_wrote_newline = False
  55. sys.stderr = Stderr()
  56. del sys, get_home_dir, is_frozen_exe
  57. INFO = 0
  58. WARNING = 1
  59. ERROR = 2
  60. CRITICAL = 3
  61. status_dict = {INFO: 'info',
  62. WARNING: 'warning',
  63. ERROR: 'error',
  64. CRITICAL: 'critical'}
  65. class BTFailure(Exception):
  66. pass
  67. class BTShutdown(BTFailure):
  68. pass