from bfs.bfs10110 import bfs10111
from bfs.bfs10110.bfs10112 import LicensingError
from bfs.bfs10110.bfs11055 import bfs11077
from bfs.bfs10063.bfs11160 import bfs11172
from helium.bfs11205 import bfs11206, bfs11204
from helium.bfs10121 import APIImpl
from helium.bfs11215 import bfs11222, bfs11220
from helium.bfs10110.bfs10112 import NoLicenseKeyFound
from helium.bfs10110.bfs11227 import bfs11237, bfs11233
from helium.bfs10110.bfs10153 import bfs10200
from helium.bfs10110.bfs11247 import bfs11271
from helium.bfs10063.path import bfs11303
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(bfs11311, value, traceback):
  if isinstance(value, LicensingError):
    print(value.message)
  else:
    sys.__excepthook__(bfs11311, value, traceback)


sys.excepthook = excepthook
def bfs11316():
  global bfs11313
  if (bfs11313 is None):
    if bfs11220():
      bfs11313 = bfs11312()
    else:
      bfs11313 = bfs11314()


  return bfs11313

bfs11313 = None
class bfs11315(object):
  def __init__(self):
    self.bfs11317()
    self.bfs10121 = None

  def bfs11317(self):
    raise NotImplementedError()

  def APIImpl(self):
    if (self.bfs10121 is None):
      self.bfs10121 = APIImpl(self.bfs11222(), self.License(), self.bfs11320())

    return self.bfs10121

  def License(self):
    raise NotImplementedError()

  def bfs11222(self):
    raise NotImplementedError()

  def bfs11320(self):
    raise NotImplementedError()


class bfs11312(bfs11315):
  def __init__(self):
    super(bfs11312, self).__init__()
    self.license = self.bfs10422 = None

  def bfs11317(self):
    bfs11321 = StreamHandler()
    bfs11322 = Formatter('%(name)s %(levelname)s: %(message)s')
    bfs11321.setFormatter(bfs11322)
    getLogger('helium').addHandler(bfs11321)
    getLogger('bfs').addHandler(bfs11321)

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

    return self.license

  def bfs11222(self):
    if (self.bfs10422 is None):
      bfs11323 = join(dirname(__file__), pardir, pardir, pardir, pardir, pardir)
      def bfs11324(bfs11325):
        return normpath(join(bfs11323, *bfs11325.split('/')))

      return bfs11222(bfs11324('../src/main/resources/base'), bfs11324('../src/main/resources'))

    return self.bfs10422

  def bfs11320(self):
    return None


class bfs11314(bfs11315):
  def __init__(self):
    self.bfs11250 = self.bfs11160 = self.license = self.bfs10425 = self.uuid = self.bfs11326 = self.bfs11245 = self.bfs11247 = self.bfs10422 = None
    super(bfs11314, self).__init__()

  def bfs11317(self):
    import helium.logging_
    bfs11330 = self.bfs11222().bfs10437('logging.conf')
    if exists(bfs11330):
      logging.config.fileConfig(bfs11330)


  def bfs11172(self):
    if (self.bfs11160 is None):
      self.bfs11160 = bfs11172()

    return self.bfs11160

  def License(self):
    if (self.license is None):
      self.license = bfs11237(self.bfs11077(), self.bfs11172(), self.bfs11271(), self.bfs11327())

    return self.license

  def bfs11320(self):
    if (self.bfs10425 is None):
      bfs11212 = self.bfs11206().bfs11212
      bfs11213 = self.bfs11206().bfs11213
      bfs11214 = self.bfs11206().bfs11214
      version = self.bfs11206().bfs11211
      bfs11331 = {'version': version, 'computer_name': self.bfs11172().bfs11177(), 'identifier': self.UUID()}
      self.bfs10425 = bfs10200(('http://%s:%s%slicenses/verify?' % (bfs11212, bfs11213, bfs11214)), bfs11331)

    return self.bfs10425

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

  def bfs11327(self):
    self.bfs11332()
    return self.bfs11250

  def bfs11332(self):
    bfs11333 = self.bfs11222().bfs10437('uuid')
    if exists(bfs11333):
      with open(bfs11333) as bfs11335:
        self.uuid = UUID(bfs11335.read())
        self.bfs11250 = False

    else:
      bfs11334 = uuid1()
      with open(bfs11333, 'w') as bfs11335:
        bfs11335.write(str(bfs11334))

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


  def bfs11206(self):
    if (self.bfs11326 is None):
      self.bfs11326 = bfs11206(self.bfs11222().bfs10437(bfs11204))

    return self.bfs11326

  def bfs11077(self):
    if (self.bfs11245 is None):
      bfs11336 = 'No Helium license key found. Please contact us at contact@heliumhq.com or visit http://heliumhq.com to obtain a new one.'
      bfs11337 = join(expanduser('~'), '.helium', bfs10111)
      if (not exists(bfs11337)):
        bfs11341 = bfs11337
        bfs11337 = self.bfs11222().bfs10437(bfs10111)
        if (not exists(bfs11337)):
          raise NoLicenseKeyFound(bfs11336)

        bfs11303(dirname(bfs11341))
        copyfile(bfs11337, bfs11341)

      self.bfs11245 = bfs11077(bfs11337)

    return self.bfs11245

  def bfs11271(self):
    if (self.bfs11247 is None):
      self.bfs11247 = bfs11271()

    return self.bfs11247

  def bfs11222(self):
    if (self.bfs10422 is None):
      bfs11340 = dirname(helium.__file__)
      bfs11342 = join(bfs11340, 'data')
      bfs11343 = (bfs11342 if exists(bfs11342) else bfs11340)
      self.bfs10422 = bfs11222(bfs11343)

    return self.bfs10422


