from bfs.bfs10143 import bfs10145
from bfs.bfs10143.bfs10147 import LicensingError
from bfs.bfs10143.bfs10230 import bfs11165
from bfs.bfs10063.bfs10227 import bfs11261
from helium.bfs11271 import bfs11272, bfs11273
from helium.bfs10155 import APIImpl
from helium.bfs11302 import bfs11306, bfs11305
from helium.bfs10143.bfs10147 import NoLicenseKeyFound
from helium.bfs10143.bfs11314 import bfs11325, bfs11321
from helium.bfs10143.bfs10221 import bfs10245
from helium.bfs10143.bfs11335 import bfs11356
from helium.bfs10063.path import bfs11372
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(bfs11401, value, traceback):
  if isinstance(value, LicensingError):
    print value.message
  else:
    sys.__excepthook__(bfs11401, value, traceback)


sys.excepthook = excepthook
def bfs11405():
  global bfs11400
  if (bfs11400 is None):
    if bfs11305():
      bfs11400 = bfs11402()
    else:
      bfs11400 = bfs11403()


  return bfs11400

bfs11400 = None
class bfs11404(object):
  def __init__(self):
    self.bfs11406()
    self.bfs10155 = None

  def bfs11406(self):
    raise NotImplementedError()

  def APIImpl(self):
    if (self.bfs10155 is None):
      self.bfs10155 = APIImpl(self.bfs11306(), self.License(), self.bfs11407())

    return self.bfs10155

  def License(self):
    raise NotImplementedError()

  def bfs11306(self):
    raise NotImplementedError()

  def bfs11407(self):
    raise NotImplementedError()


class bfs11402(bfs11404):
  def __init__(self):
    super(bfs11402, self).__init__()
    self.license = self.bfs10472 = None

  def bfs11406(self):
    bfs11411 = StreamHandler()
    bfs11410 = Formatter('%(name)s %(levelname)s: %(message)s')
    bfs11411.setFormatter(bfs11410)
    getLogger('helium').addHandler(bfs11411)
    getLogger('bfs').addHandler(bfs11411)

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

    return self.license

  def bfs11306(self):
    if (self.bfs10472 is None):
      bfs11412 = join(dirname(__file__), pardir, pardir, pardir, pardir, pardir)
      def bfs11415(bfs11413):
        return normpath(join(bfs11412, *bfs11413.split('/')))

      return bfs11306(bfs11415('../src/main/resources/base'), bfs11415('../src/main/resources'))

    return self.bfs10472

  def bfs11407(self):
    return None


class bfs11403(bfs11404):
  def __init__(self):
    self.bfs11334 = self.bfs10227 = self.license = self.bfs10474 = self.uuid = self.bfs11414 = self.bfs11333 = self.bfs11335 = self.bfs10472 = None
    super(bfs11403, self).__init__()

  def bfs11406(self):
    import helium.logging_
    bfs11416 = self.bfs11306().bfs10507('logging.conf')
    if exists(bfs11416):
      logging.config.fileConfig(bfs11416)


  def bfs11261(self):
    if (self.bfs10227 is None):
      self.bfs10227 = bfs11261()

    return self.bfs10227

  def License(self):
    if (self.license is None):
      self.license = bfs11325(self.bfs11165(), self.bfs11261(), self.bfs11356(), self.bfs11417())

    return self.license

  def bfs11407(self):
    if (self.bfs10474 is None):
      bfs11276 = self.bfs11272().bfs11276
      bfs11300 = self.bfs11272().bfs11300
      bfs11301 = self.bfs11272().bfs11301
      version = self.bfs11272().bfs11277
      bfs11420 = {'version': version, 'computer_name': self.bfs11261().bfs11263(), 'identifier': self.UUID()}
      self.bfs10474 = bfs10245(('http://%s:%s%slicenses/verify?' % (bfs11276, bfs11300, bfs11301)), bfs11420)

    return self.bfs10474

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

  def bfs11417(self):
    self.bfs11421()
    return self.bfs11334

  def bfs11421(self):
    bfs11423 = self.bfs11306().bfs10507('uuid')
    if exists(bfs11423):
      with open(bfs11423) as bfs11422:
        self.uuid = UUID(bfs11422.read())
        self.bfs11334 = False

    else:
      bfs11424 = uuid1()
      with open(bfs11423, 'w') as bfs11422:
        bfs11422.write(str(bfs11424))

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


  def bfs11272(self):
    if (self.bfs11414 is None):
      self.bfs11414 = bfs11272(self.bfs11306().bfs10507(bfs11273))

    return self.bfs11414

  def bfs11165(self):
    if (self.bfs11333 is None):
      bfs11426 = 'No Helium license key found. Please contact us at contact@heliumhq.com or visit http://heliumhq.com to obtain a new one.'
      bfs11425 = join(expanduser('~'), '.helium', bfs10145)
      if (not exists(bfs11425)):
        bfs11427 = bfs11425
        bfs11425 = self.bfs11306().bfs10507(bfs10145)
        if (not exists(bfs11425)):
          raise NoLicenseKeyFound(bfs11426)

        bfs11372(dirname(bfs11427))
        copyfile(bfs11425, bfs11427)

      self.bfs11333 = bfs11165(bfs11425)

    return self.bfs11333

  def bfs11356(self):
    if (self.bfs11335 is None):
      self.bfs11335 = bfs11356()

    return self.bfs11335

  def bfs11306(self):
    if (self.bfs10472 is None):
      bfs11430 = dirname(helium.__file__)
      bfs11431 = join(bfs11430, 'data')
      bfs11432 = (bfs11431 if exists(bfs11431) else bfs11430)
      self.bfs10472 = bfs11306(bfs11432)

    return self.bfs10472


