from bfs.bfs10143 import bfs10145
from bfs.bfs10143.bfs10147 import LicensingError
from bfs.bfs10143.bfs11140 import bfs11161
from bfs.bfs10063.bfs11243 import bfs11256
from helium.bfs11266 import bfs11270, bfs11267
from helium.bfs10155 import APIImpl
from helium.bfs11276 import bfs11304, bfs11302
from helium.bfs10143.bfs10147 import NoLicenseKeyFound
from helium.bfs10143.bfs11311 import bfs11321, bfs11315
from helium.bfs10143.bfs10221 import bfs10245
from helium.bfs10143.bfs11331 import bfs11353
from helium.bfs10063.path import bfs11366
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(bfs11374, value, traceback):
  if isinstance(value, LicensingError):
    print value.message
  else:
    sys.__excepthook__(bfs11374, value, traceback)


sys.excepthook = excepthook
def bfs11377():
  global bfs11373
  if (bfs11373 is None):
    if bfs11302():
      bfs11373 = bfs11375()
    else:
      bfs11373 = bfs11376()


  return bfs11373

bfs11373 = None
class bfs11401(object):
  def __init__(self):
    self.bfs11400()
    self.bfs10155 = None

  def bfs11400(self):
    raise NotImplementedError()

  def APIImpl(self):
    if (self.bfs10155 is None):
      self.bfs10155 = APIImpl(self.bfs11304(), self.License(), self.bfs11402())

    return self.bfs10155

  def License(self):
    raise NotImplementedError()

  def bfs11304(self):
    raise NotImplementedError()

  def bfs11402(self):
    raise NotImplementedError()


class bfs11375(bfs11401):
  def __init__(self):
    super(bfs11375, self).__init__()
    self.license = self.bfs10472 = None

  def bfs11400(self):
    bfs11403 = StreamHandler()
    bfs11405 = Formatter('%(name)s %(levelname)s: %(message)s')
    bfs11403.setFormatter(bfs11405)
    getLogger('helium').addHandler(bfs11403)
    getLogger('bfs').addHandler(bfs11403)

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

    return self.license

  def bfs11304(self):
    if (self.bfs10472 is None):
      bfs11404 = join(dirname(__file__), pardir, pardir, pardir, pardir, pardir)
      def bfs11407(bfs11406):
        return normpath(join(bfs11404, *bfs11406.split('/')))

      return bfs11304(bfs11407('../src/main/resources/base'), bfs11407('../src/main/resources'))

    return self.bfs10472

  def bfs11402(self):
    return None


class bfs11376(bfs11401):
  def __init__(self):
    self.bfs11332 = self.bfs11243 = self.license = self.bfs10474 = self.uuid = self.bfs11411 = self.bfs11327 = self.bfs11331 = self.bfs10472 = None
    super(bfs11376, self).__init__()

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


  def bfs11256(self):
    if (self.bfs11243 is None):
      self.bfs11243 = bfs11256()

    return self.bfs11243

  def License(self):
    if (self.license is None):
      self.license = bfs11321(self.bfs11161(), self.bfs11256(), self.bfs11353(), self.bfs11412())

    return self.license

  def bfs11402(self):
    if (self.bfs10474 is None):
      bfs11274 = self.bfs11270().bfs11274
      bfs11275 = self.bfs11270().bfs11275
      bfs11277 = self.bfs11270().bfs11277
      version = self.bfs11270().bfs11272
      bfs11413 = {'version': version, 'computer_name': self.bfs11256().bfs11261(), 'identifier': self.UUID()}
      self.bfs10474 = bfs10245(('http://%s:%s%slicenses/verify?' % (bfs11274, bfs11275, bfs11277)), bfs11413)

    return self.bfs10474

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

  def bfs11412(self):
    self.bfs11415()
    return self.bfs11332

  def bfs11415(self):
    bfs11414 = self.bfs11304().bfs10507('uuid')
    if exists(bfs11414):
      with open(bfs11414) as bfs11416:
        self.uuid = UUID(bfs11416.read())
        self.bfs11332 = False

    else:
      bfs11417 = uuid1()
      with open(bfs11414, 'w') as bfs11416:
        bfs11416.write(str(bfs11417))

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


  def bfs11270(self):
    if (self.bfs11411 is None):
      self.bfs11411 = bfs11270(self.bfs11304().bfs10507(bfs11267))

    return self.bfs11411

  def bfs11161(self):
    if (self.bfs11327 is None):
      bfs11420 = 'No Helium license key found. Please contact us at contact@heliumhq.com or visit http://heliumhq.com to obtain a new one.'
      bfs11421 = join(expanduser('~'), '.helium', bfs10145)
      if (not exists(bfs11421)):
        bfs11423 = bfs11421
        bfs11421 = self.bfs11304().bfs10507(bfs10145)
        if (not exists(bfs11421)):
          raise NoLicenseKeyFound(bfs11420)

        bfs11366(dirname(bfs11423))
        copyfile(bfs11421, bfs11423)

      self.bfs11327 = bfs11161(bfs11421)

    return self.bfs11327

  def bfs11353(self):
    if (self.bfs11331 is None):
      self.bfs11331 = bfs11353()

    return self.bfs11331

  def bfs11304(self):
    if (self.bfs10472 is None):
      bfs11422 = dirname(helium.__file__)
      bfs11424 = join(bfs11422, 'data')
      bfs11426 = (bfs11424 if exists(bfs11424) else bfs11422)
      self.bfs10472 = bfs11304(bfs11426)

    return self.bfs10472


