from bfs.bfs10143 import bfs10145
from bfs.bfs10143.bfs10147 import LicensingError
from bfs.bfs10143.bfs10230 import bfs11170
from bfs.bfs10063.bfs10227 import bfs11263
from helium.bfs11274 import bfs11277, bfs11275
from helium.bfs10155 import APIImpl
from helium.bfs11305 import bfs11311, bfs11307
from helium.bfs10143.bfs10147 import NoLicenseKeyFound
from helium.bfs10143.bfs11317 import bfs11330, bfs11325
from helium.bfs10143.bfs10221 import bfs10245
from helium.bfs10143.bfs11337 import bfs11361
from helium.bfs10063.path import bfs11375
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(bfs11403, value, traceback):
  if isinstance(value, LicensingError):
    print(value.message)
  else:
    sys.__excepthook__(bfs11403, value, traceback)


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


  return bfs11405

bfs11405 = None
class bfs11411(object):
  def __init__(self):
    self.bfs11410()
    self.bfs10155 = None

  def bfs11410(self):
    raise NotImplementedError()

  def APIImpl(self):
    if (self.bfs10155 is None):
      self.bfs10155 = APIImpl(self.bfs11311(), self.License(), self.bfs11412())

    return self.bfs10155

  def License(self):
    raise NotImplementedError()

  def bfs11311(self):
    raise NotImplementedError()

  def bfs11412(self):
    raise NotImplementedError()


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

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

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

    return self.license

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

      return bfs11311(bfs11417('../src/main/resources/base'), bfs11417('../src/main/resources'))

    return self.bfs10472

  def bfs11412(self):
    return None


class bfs11406(bfs11411):
  def __init__(self):
    self.bfs11341 = self.bfs10227 = self.license = self.bfs10474 = self.uuid = self.bfs11420 = self.bfs11336 = self.bfs11337 = self.bfs10472 = None
    super(bfs11406, self).__init__()

  def bfs11410(self):
    import helium.logging_
    bfs11421 = self.bfs11311().bfs10507('logging.conf')
    if exists(bfs11421):
      logging.config.fileConfig(bfs11421)


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

    return self.bfs10227

  def License(self):
    if (self.license is None):
      self.license = bfs11330(self.bfs11170(), self.bfs11263(), self.bfs11361(), self.bfs11423())

    return self.license

  def bfs11412(self):
    if (self.bfs10474 is None):
      bfs11302 = self.bfs11277().bfs11302
      bfs11304 = self.bfs11277().bfs11304
      bfs11303 = self.bfs11277().bfs11303
      version = self.bfs11277().bfs11301
      bfs11422 = {'version': version, 'computer_name': self.bfs11263().bfs11266(), 'identifier': self.UUID()}
      self.bfs10474 = bfs10245(('http://%s:%s%slicenses/verify?' % (bfs11302, bfs11304, bfs11303)), bfs11422)

    return self.bfs10474

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

  def bfs11423(self):
    self.bfs11424()
    return self.bfs11341

  def bfs11424(self):
    bfs11426 = self.bfs11311().bfs10507('uuid')
    if exists(bfs11426):
      with open(bfs11426) as bfs11425:
        self.uuid = UUID(bfs11425.read())
        self.bfs11341 = False

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

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


  def bfs11277(self):
    if (self.bfs11420 is None):
      self.bfs11420 = bfs11277(self.bfs11311().bfs10507(bfs11275))

    return self.bfs11420

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

        bfs11375(dirname(bfs11432))
        copyfile(bfs11431, bfs11432)

      self.bfs11336 = bfs11170(bfs11431)

    return self.bfs11336

  def bfs11361(self):
    if (self.bfs11337 is None):
      self.bfs11337 = bfs11361()

    return self.bfs11337

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

    return self.bfs10472


