from bfs.bfs10143 import bfs10145
from bfs.bfs10143.bfs10147 import LicensingError
from bfs.bfs10143.bfs11132 import bfs11152
from bfs.bfs10063.bfs11235 import bfs11247
from helium.bfs11261 import bfs11262, bfs11260
from helium.bfs10155 import APIImpl
from helium.bfs11271 import bfs11275, bfs11274
from helium.bfs10143.bfs10147 import NoLicenseKeyFound
from helium.bfs10143.bfs11304 import bfs11312, bfs11307
from helium.bfs10143.bfs10221 import bfs10245
from helium.bfs10143.bfs11323 import bfs11346
from helium.bfs10063.path import bfs11357
from logging import StreamHandler, Formatter, getLogger
from os.path import pardir, join, exists, dirname, normpath, expanduser
from shutil import copyfile
from uuid import uuid1, UUID
import helium
import logging.config
import sys
def excepthook(bfs11364, value, traceback):
  if isinstance(value, LicensingError):
    print value.message
  else:
    sys.__excepthook__(bfs11364, value, traceback)


sys.excepthook = excepthook
def bfs11370():
  global bfs11366
  if (bfs11366 is None):
    if bfs11274():
      bfs11366 = bfs11367()
    else:
      bfs11366 = bfs11371()


  return bfs11366

bfs11366 = None
class bfs11372(object):
  def __init__(self):
    self.bfs11374()
    self.bfs10155 = None

  def bfs11374(self):
    raise NotImplementedError()

  def APIImpl(self):
    if (self.bfs10155 is None):
      self.bfs10155 = APIImpl(self.bfs11275(), self.License(), self.bfs11373())

    return self.bfs10155

  def License(self):
    raise NotImplementedError()

  def bfs11275(self):
    raise NotImplementedError()

  def bfs11373(self):
    raise NotImplementedError()


class bfs11367(bfs11372):
  def __init__(self):
    super(bfs11367, self).__init__()
    self.license = self.bfs10472 = None

  def bfs11374(self):
    bfs11375 = StreamHandler()
    bfs11376 = Formatter('%(name)s %(levelname)s: %(message)s')
    bfs11375.setFormatter(bfs11376)
    getLogger('helium').addHandler(bfs11375)
    getLogger('bfs').addHandler(bfs11375)

  def License(self):
    if (self.license is None):
      self.license = bfs11307()

    return self.license

  def bfs11275(self):
    if (self.bfs10472 is None):
      bfs11377 = join(dirname(__file__), pardir, pardir, pardir, pardir, pardir)
      def bfs11400(bfs11401):
        return normpath(join(bfs11377, *bfs11401.split('/')))

      return bfs11275(bfs11400('../src/main/resources/base'), bfs11400('../src/main/resources'))

    return self.bfs10472

  def bfs11373(self):
    return None


class bfs11371(bfs11372):
  def __init__(self):
    self.bfs11325 = self.bfs11235 = self.license = self.bfs10474 = self.uuid = self.bfs11402 = self.bfs11322 = self.bfs11323 = self.bfs10472 = None
    super(bfs11371, self).__init__()

  def bfs11374(self):
    import helium.logging_
    bfs11403 = self.bfs11275().bfs10507('logging.conf')
    if exists(bfs11403):
      logging.config.fileConfig(bfs11403)


  def bfs11247(self):
    if (self.bfs11235 is None):
      self.bfs11235 = bfs11247()

    return self.bfs11235

  def License(self):
    if (self.license is None):
      self.license = bfs11312(self.bfs11152(), self.bfs11247(), self.bfs11346(), self.bfs11405())

    return self.license

  def bfs11373(self):
    if (self.bfs10474 is None):
      bfs11266 = self.bfs11262().bfs11266
      bfs11267 = self.bfs11262().bfs11267
      bfs11270 = self.bfs11262().bfs11270
      version = self.bfs11262().bfs11264
      bfs11404 = {'version': version, 'computer_name': self.bfs11247().bfs11253(), 'identifier': self.UUID()}
      self.bfs10474 = bfs10245(('http://%s:%s%slicenses/verify?' % (bfs11266, bfs11267, bfs11270)), bfs11404)

    return self.bfs10474

  def UUID(self):
    self.bfs11406()
    return self.uuid

  def bfs11405(self):
    self.bfs11406()
    return self.bfs11325

  def bfs11406(self):
    bfs11407 = self.bfs11275().bfs10507('uuid')
    if exists(bfs11407):
      with open(bfs11407) as bfs11411:
        self.uuid = UUID(bfs11411.read())
        self.bfs11325 = False

    else:
      bfs11410 = uuid1()
      with open(bfs11407, 'w') as bfs11411:
        bfs11411.write(str(bfs11410))

      self.uuid = uuid1()
      self.bfs11325 = True


  def bfs11262(self):
    if (self.bfs11402 is None):
      self.bfs11402 = bfs11262(self.bfs11275().bfs10507(bfs11260))

    return self.bfs11402

  def bfs11152(self):
    if (self.bfs11322 is None):
      bfs11412 = 'No Helium license key found. Please contact us at contact@heliumhq.com or visit http://heliumhq.com to obtain a new one.'
      bfs11413 = join(expanduser('~'), '.helium', bfs10145)
      if (not exists(bfs11413)):
        bfs11415 = bfs11413
        bfs11413 = self.bfs11275().bfs10507(bfs10145)
        if (not exists(bfs11413)):
          raise NoLicenseKeyFound(bfs11412)

        bfs11357(dirname(bfs11415))
        copyfile(bfs11413, bfs11415)

      self.bfs11322 = bfs11152(bfs11413)

    return self.bfs11322

  def bfs11346(self):
    if (self.bfs11323 is None):
      self.bfs11323 = bfs11346()

    return self.bfs11323

  def bfs11275(self):
    if (self.bfs10472 is None):
      bfs11414 = dirname(helium.__file__)
      bfs11416 = join(bfs11414, 'data')
      bfs11417 = (bfs11416 if exists(bfs11416) else bfs11414)
      self.bfs10472 = bfs11275(bfs11417)

    return self.bfs10472


