from bfs.bfs10143 import bfs10145
from bfs.bfs10143.bfs10147 import LicensingError
from bfs.bfs10143.bfs10230 import bfs11172
from bfs.bfs10063.bfs10227 import bfs11270
from helium.bfs11301 import bfs11304, bfs11302
from helium.bfs10155 import APIImpl
from helium.bfs11313 import bfs11315, bfs11316
from helium.bfs10143.bfs10147 import NoLicenseKeyFound
from helium.bfs10143.bfs11325 import bfs11335, bfs11331
from helium.bfs10143.bfs10221 import bfs10245
from helium.bfs10143.bfs11344 import bfs11366
from helium.bfs10063.path import bfs11402
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(bfs11411, value, traceback):
  if isinstance(value, LicensingError):
    print value.message
  else:
    sys.__excepthook__(bfs11411, value, traceback)


sys.excepthook = excepthook
def bfs11415():
  global bfs11410
  if (bfs11410 is None):
    if bfs11316():
      bfs11410 = bfs11412()
    else:
      bfs11410 = bfs11413()


  return bfs11410

bfs11410 = None
class bfs11414(object):
  def __init__(self):
    self.bfs11416()
    self.bfs10155 = None

  def bfs11416(self):
    raise NotImplementedError()

  def APIImpl(self):
    if (self.bfs10155 is None):
      self.bfs10155 = APIImpl(self.bfs11315(), self.License(), self.bfs11417())

    return self.bfs10155

  def License(self):
    raise NotImplementedError()

  def bfs11315(self):
    raise NotImplementedError()

  def bfs11417(self):
    raise NotImplementedError()


class bfs11412(bfs11414):
  def __init__(self):
    super(bfs11412, self).__init__()
    self.license = self.bfs10500 = None

  def bfs11416(self):
    bfs11420 = StreamHandler()
    bfs11421 = Formatter('%(name)s %(levelname)s: %(message)s')
    bfs11420.setFormatter(bfs11421)
    getLogger('helium').addHandler(bfs11420)
    getLogger('bfs').addHandler(bfs11420)

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

    return self.license

  def bfs11315(self):
    if (self.bfs10500 is None):
      bfs11423 = join(dirname(__file__), pardir, pardir, pardir, pardir, pardir)
      def bfs11424(bfs11422):
        return normpath(join(bfs11423, *bfs11422.split('/')))

      return bfs11315(bfs11424('../src/main/resources/base'), bfs11424('../src/main/resources'))

    return self.bfs10500

  def bfs11417(self):
    return None


class bfs11413(bfs11414):
  def __init__(self):
    self.bfs11346 = self.bfs10227 = self.license = self.bfs10503 = self.uuid = self.bfs11426 = self.bfs11343 = self.bfs11344 = self.bfs10500 = None
    super(bfs11413, self).__init__()

  def bfs11416(self):
    import helium.logging_
    bfs11425 = self.bfs11315().bfs10514('logging.conf')
    if exists(bfs11425):
      logging.config.fileConfig(bfs11425)


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

    return self.bfs10227

  def License(self):
    if (self.license is None):
      self.license = bfs11335(self.bfs11172(), self.bfs11270(), self.bfs11366(), self.bfs11427())

    return self.license

  def bfs11417(self):
    if (self.bfs10503 is None):
      bfs11310 = self.bfs11304().bfs11310
      bfs11307 = self.bfs11304().bfs11307
      bfs11311 = self.bfs11304().bfs11311
      version = self.bfs11304().bfs11306
      bfs11430 = {'version': version, 'computer_name': self.bfs11270().bfs11272(), 'identifier': self.UUID()}
      self.bfs10503 = bfs10245(('http://%s:%s%slicenses/verify?' % (bfs11310, bfs11307, bfs11311)), bfs11430)

    return self.bfs10503

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

  def bfs11427(self):
    self.bfs11431()
    return self.bfs11346

  def bfs11431(self):
    bfs11432 = self.bfs11315().bfs10514('uuid')
    if exists(bfs11432):
      with open(bfs11432) as bfs11433:
        self.uuid = UUID(bfs11433.read())
        self.bfs11346 = False

    else:
      bfs11435 = uuid1()
      with open(bfs11432, 'w') as bfs11433:
        bfs11433.write(str(bfs11435))

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


  def bfs11304(self):
    if (self.bfs11426 is None):
      self.bfs11426 = bfs11304(self.bfs11315().bfs10514(bfs11302))

    return self.bfs11426

  def bfs11172(self):
    if (self.bfs11343 is None):
      bfs11434 = 'No Helium license key found. Please contact us at contact@heliumhq.com or visit http://heliumhq.com to obtain a new one.'
      bfs11436 = join(expanduser('~'), '.helium', bfs10145)
      if (not exists(bfs11436)):
        bfs11440 = bfs11436
        bfs11436 = self.bfs11315().bfs10514(bfs10145)
        if (not exists(bfs11436)):
          raise NoLicenseKeyFound(bfs11434)

        bfs11402(dirname(bfs11440))
        copyfile(bfs11436, bfs11440)

      self.bfs11343 = bfs11172(bfs11436)

    return self.bfs11343

  def bfs11366(self):
    if (self.bfs11344 is None):
      self.bfs11344 = bfs11366()

    return self.bfs11344

  def bfs11315(self):
    if (self.bfs10500 is None):
      bfs11437 = dirname(helium.__file__)
      bfs11441 = join(bfs11437, 'data')
      bfs11442 = (bfs11441 if exists(bfs11441) else bfs11437)
      self.bfs10500 = bfs11315(bfs11442)

    return self.bfs10500


