from bfs.bfs10135 import bfs10134
from bfs.bfs10135.errors import bfs10136
from bfs.bfs10135.bfs11063 import bfs11104
from bfs.bfs10077.bfs11170 import bfs11173
from helium.bfs11201 import bfs11205, bfs11203
from helium.bfs10146 import APIImpl
from helium.bfs10052 import bfs10056, bfs10055
from helium.bfs10135.errors import bfs10172
from helium.bfs10135.bfs11213 import bfs11223, bfs11220
from helium.bfs10135.bfs10202 import bfs10220
from helium.bfs10135.bfs11234 import bfs11256
from os.path import pardir, join, exists, dirname, normpath
from springpython.config import Object, PythonConfig
from springpython.context import ApplicationContext
from uuid import uuid1, UUID
import helium
import logging
import sys
def excepthook(bfs11266, value, traceback):
  if isinstance(value, bfs10136):
    print(value.message)
  else:
    sys.__excepthook__(bfs11266, value, traceback)


sys.excepthook = excepthook
bfs10107 = logging.getLogger(__name__)
bfs10107.setLevel(logging.INFO)
bfs11267 = None
def bfs11273():
  global bfs11267
  if (bfs11267 is None):
    bfs10107.info('Starting Helium')
    bfs11267 = ApplicationContext((bfs11270() if bfs10055() else bfs11271())
)

  return bfs11267

class bfs11272(PythonConfig):
  @Object(lazy_init=True)
  def APIImpl(self):
    return APIImpl(self.bfs10056(), self.License(), self.bfs11274())

  @Object
  def License(self):
    raise NotImplementedError()

  @Object
  def bfs10056(self):
    raise NotImplementedError()

  @Object
  def bfs11274(self):
    raise NotImplementedError()


class bfs11270(bfs11272):
  @Object
  def License(self):
    return bfs11220()

  @Object
  def bfs10056(self):
    bfs11275 = join(dirname(__file__), pardir, pardir, pardir, pardir, pardir)
    def bfs11276(bfs11277):
      return normpath(join(bfs11275, *bfs11277.split('/')))

    return bfs10056(bfs11276('../src/main/resources/base'), bfs11276('../src/main/resources'))

  @Object
  def bfs11274(self):
    return None


class bfs11271(bfs11272):
  @Object
  def bfs11173(self):
    return bfs11173()

  @Object
  def License(self):
    return bfs11223(self.bfs11104(), self.bfs11173(), self.bfs11256(), self.bfs11300())

  @Object
  def bfs11274(self):
    bfs11207 = self.bfs11205().bfs11207
    bfs11211 = self.bfs11205().bfs11211
    bfs11212 = self.bfs11205().bfs11212
    version = self.bfs11205().bfs11210
    bfs11301 = {'version': version, 'computer_name': self.bfs11173().bfs11175(), 'identifier': self.UUID()}
    return bfs10220(('http://%s:%s%slicenses/verify?' % (bfs11207, bfs11211, bfs11212)), bfs11301)

  @Object
  def UUID(self):
    return self.bfs11302()[0]

  @Object
  def bfs11300(self):
    return self.bfs11302()[1]

  @Object
  def bfs11302(self):
    bfs11304 = self.bfs10056().bfs10063('uuid')
    if exists(bfs11304):
      with open(bfs11304) as bfs11303:
        return [UUID(bfs11303.read()), False]

    else:
      bfs11305 = uuid1()
      with open(bfs11304, 'w') as bfs11303:
        bfs11303.write(str(bfs11305))

      return [bfs11305, True]


  @Object
  def bfs11205(self):
    return bfs11205(self.bfs10056().bfs10063(bfs11203))

  @Object
  def bfs11104(self):
    bfs11306 = 'No Helium license key found. Please contact us at contact@heliumhq.com or visit http://heliumhq.com to obtain a new one.'
    bfs11310 = self.bfs10056().bfs10063(bfs10134)
    if (not exists(bfs11310)):
      raise bfs10172(bfs11306)

    return bfs11104(bfs11310)

  @Object
  def bfs11256(self):
    return bfs11256()

  @Object
  def bfs10056(self):
    bfs11307 = dirname(helium.__file__)
    bfs11311 = join(bfs11307, 'data')
    bfs11313 = (bfs11311 if exists(bfs11311) else bfs11307)

    bfs10107.info(('Helium home is %s.' % bfs11313))
    return bfs10056(bfs11313)


