from bfs.bfs10143 import bfs10145
from bfs.bfs10143.bfs10147 import LicensingError
from bfs.bfs10143.bfs11146 import bfs11164
from bfs.bfs10063.bfs11250 import bfs11262
from helium.bfs11272 import bfs11275, bfs11274
from helium.bfs10155 import APIImpl
from helium.bfs11303 import bfs11307, bfs11310
from helium.bfs10143.bfs10147 import NoLicenseKeyFound
from helium.bfs10143.bfs11315 import bfs11326, bfs11323
from helium.bfs10143.bfs10221 import bfs10245
from helium.bfs10143.bfs11336 import bfs11357
from helium.bfs10063.path import bfs11373
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(bfs11402, value, traceback):
  if isinstance(value, LicensingError):
    print(value.message)
  else:
    sys.__excepthook__(bfs11402, value, traceback)


sys.excepthook = excepthook
def bfs11406():
  global bfs11403
  if (bfs11403 is None):
    if bfs11310():
      bfs11403 = bfs11405()
    else:
      bfs11403 = bfs11404()


  return bfs11403

bfs11403 = None
class bfs11407(object):
  def __init__(self):
    self.bfs11411()
    self.bfs10155 = None

  def bfs11411(self):
    raise NotImplementedError()

  def APIImpl(self):
    if (self.bfs10155 is None):
      self.bfs10155 = APIImpl(self.bfs11307(), self.License(), self.bfs11410())

    return self.bfs10155

  def License(self):
    raise NotImplementedError()

  def bfs11307(self):
    raise NotImplementedError()

  def bfs11410(self):
    raise NotImplementedError()


class bfs11405(bfs11407):
  def __init__(self):
    super(bfs11405, self).__init__()
    self.license = self.bfs10472 = None

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

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

    return self.license

  def bfs11307(self):
    if (self.bfs10472 is None):
      bfs11415 = join(dirname(__file__), pardir, pardir, pardir, pardir, pardir)
      def bfs11416(bfs11414):
        return normpath(join(bfs11415, *bfs11414.split('/')))

      return bfs11307(bfs11416('../src/main/resources/base'), bfs11416('../src/main/resources'))

    return self.bfs10472

  def bfs11410(self):
    return None


class bfs11404(bfs11407):
  def __init__(self):
    self.bfs11337 = self.bfs11250 = self.license = self.bfs10474 = self.uuid = self.bfs11417 = self.bfs11334 = self.bfs11336 = self.bfs10472 = None
    super(bfs11404, self).__init__()

  def bfs11411(self):
    import helium.logging_
    bfs11420 = self.bfs11307().bfs10507('logging.conf')
    if exists(bfs11420):
      logging.config.fileConfig(bfs11420)


  def bfs11262(self):
    if (self.bfs11250 is None):
      self.bfs11250 = bfs11262()

    return self.bfs11250

  def License(self):
    if (self.license is None):
      self.license = bfs11326(self.bfs11164(), self.bfs11262(), self.bfs11357(), self.bfs11421())

    return self.license

  def bfs11410(self):
    if (self.bfs10474 is None):
      bfs11301 = self.bfs11275().bfs11301
      bfs11302 = self.bfs11275().bfs11302
      bfs11304 = self.bfs11275().bfs11304
      version = self.bfs11275().bfs11300
      bfs11423 = {'version': version, 'computer_name': self.bfs11262().bfs11264(), 'identifier': self.UUID()}
      self.bfs10474 = bfs10245(('http://%s:%s%slicenses/verify?' % (bfs11301, bfs11302, bfs11304)), bfs11423)

    return self.bfs10474

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

  def bfs11421(self):
    self.bfs11422()
    return self.bfs11337

  def bfs11422(self):
    bfs11424 = self.bfs11307().bfs10507('uuid')
    if exists(bfs11424):
      with open(bfs11424) as bfs11426:
        self.uuid = UUID(bfs11426.read())
        self.bfs11337 = False

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

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


  def bfs11275(self):
    if (self.bfs11417 is None):
      self.bfs11417 = bfs11275(self.bfs11307().bfs10507(bfs11274))

    return self.bfs11417

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

        bfs11373(dirname(bfs11431))
        copyfile(bfs11430, bfs11431)

      self.bfs11334 = bfs11164(bfs11430)

    return self.bfs11334

  def bfs11357(self):
    if (self.bfs11336 is None):
      self.bfs11336 = bfs11357()

    return self.bfs11336

  def bfs11307(self):
    if (self.bfs10472 is None):
      bfs11432 = dirname(helium.__file__)
      bfs11433 = join(bfs11432, 'data')
      bfs11435 = (bfs11433 if exists(bfs11433) else bfs11432)
      self.bfs10472 = bfs11307(bfs11435)

    return self.bfs10472


