from bfs.bfs10101 import bfs10103
from bfs.bfs10101.bfs10102 import LicensingError
from bfs.bfs10101.bfs10145 import bfs10671
from bfs.bfs10060.bfs10147 import bfs10747
from helium.bfs10762 import bfs10763, bfs10761
from helium.bfs10112 import APIImpl
from helium.bfs10772 import bfs10776, bfs10774
from helium.bfs10101.bfs10102 import NoLicenseKeyFound
from helium.bfs10101.bfs11004 import bfs11006, bfs11005
from helium.bfs10101.bfs10144 import bfs10165
from helium.bfs10101.bfs11020 import bfs11034
from helium.bfs10060.path import bfs11044
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(bfs11051, value, traceback):
  if isinstance(value, LicensingError):
    print(value.message)
  else:
    sys.__excepthook__(bfs11051, value, traceback)


sys.excepthook = excepthook
def bfs11056():
  global bfs11053
  if (bfs11053 is None):
    if bfs10774():
      bfs11053 = bfs11052()
    else:
      bfs11053 = bfs11054()


  return bfs11053

bfs11053 = None
class bfs11055(object):
  def __init__(self):
    self.bfs11057()
    self.bfs10112 = None

  def bfs11057(self):
    raise NotImplementedError()

  def APIImpl(self):
    if (self.bfs10112 is None):
      self.bfs10112 = APIImpl(self.bfs10776(), self.License(), self.bfs11061())

    return self.bfs10112

  def License(self):
    raise NotImplementedError()

  def bfs10776(self):
    raise NotImplementedError()

  def bfs11061(self):
    raise NotImplementedError()


class bfs11052(bfs11055):
  def __init__(self):
    super(bfs11052, self).__init__()
    self.license = self.bfs10333 = None

  def bfs11057(self):
    bfs11060 = StreamHandler()
    bfs11062 = Formatter('%(name)s %(levelname)s: %(message)s')
    bfs11060.setFormatter(bfs11062)
    getLogger('helium').addHandler(bfs11060)
    getLogger('bfs').addHandler(bfs11060)

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

    return self.license

  def bfs10776(self):
    if (self.bfs10333 is None):
      bfs11064 = join(dirname(__file__), pardir, pardir, pardir, pardir, pardir)
      def bfs11065(bfs11063):
        return normpath(join(bfs11064, *bfs11063.split('/')))

      return bfs10776(bfs11065('../src/main/resources/base'), bfs11065('../src/main/resources'))

    return self.bfs10333

  def bfs11061(self):
    return None


class bfs11054(bfs11055):
  def __init__(self):
    self.bfs11017 = self.bfs10147 = self.license = self.bfs10335 = self.uuid = self.bfs11067 = self.bfs11016 = self.bfs11020 = self.bfs10333 = None
    super(bfs11054, self).__init__()

  def bfs11057(self):
    import helium.logging_
    bfs11066 = self.bfs10776().bfs10347('logging.conf')
    if exists(bfs11066):
      logging.config.fileConfig(bfs11066)


  def bfs10747(self):
    if (self.bfs10147 is None):
      self.bfs10147 = bfs10747()

    return self.bfs10147

  def License(self):
    if (self.license is None):
      self.license = bfs11006(self.bfs10671(), self.bfs10747(), self.bfs11034(), self.bfs11070())

    return self.license

  def bfs11061(self):
    if (self.bfs10335 is None):
      bfs10770 = self.bfs10763().bfs10770
      bfs10767 = self.bfs10763().bfs10767
      bfs10771 = self.bfs10763().bfs10771
      version = self.bfs10763().bfs10766
      bfs11071 = {'version': version, 'computer_name': self.bfs10747().bfs10754(), 'identifier': self.UUID()}
      self.bfs10335 = bfs10165(('http://%s:%s%slicenses/verify?' % (bfs10770, bfs10767, bfs10771)), bfs11071)

    return self.bfs10335

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

  def bfs11070(self):
    self.bfs11073()
    return self.bfs11017

  def bfs11073(self):
    bfs11072 = self.bfs10776().bfs10347('uuid')
    if exists(bfs11072):
      with open(bfs11072) as bfs11074:
        self.uuid = UUID(bfs11074.read())
        self.bfs11017 = False

    else:
      bfs10063 = uuid1()
      with open(bfs11072, 'w') as bfs11074:
        bfs11074.write(str(bfs10063))

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


  def bfs10763(self):
    if (self.bfs11067 is None):
      self.bfs11067 = bfs10763(self.bfs10776().bfs10347(bfs10761))

    return self.bfs11067

  def bfs10671(self):
    if (self.bfs11016 is None):
      bfs11075 = 'No Helium license key found. Please contact us at contact@heliumhq.com or visit http://heliumhq.com to obtain a new one.'
      bfs11077 = join(expanduser('~'), '.helium', bfs10103)
      if (not exists(bfs11077)):
        bfs11076 = bfs11077
        bfs11077 = self.bfs10776().bfs10347(bfs10103)
        if (not exists(bfs11077)):
          raise NoLicenseKeyFound(bfs11075)

        bfs11044(dirname(bfs11076))
        copyfile(bfs11077, bfs11076)

      self.bfs11016 = bfs10671(bfs11077)

    return self.bfs11016

  def bfs11034(self):
    if (self.bfs11020 is None):
      self.bfs11020 = bfs11034()

    return self.bfs11020

  def bfs10776(self):
    if (self.bfs10333 is None):
      bfs11100 = dirname(helium.__file__)
      bfs11102 = join(bfs11100, 'data')
      bfs11101 = (bfs11102 if exists(bfs11102) else bfs11100)

      self.bfs10333 = bfs10776(bfs11101)

    return self.bfs10333


