import logging
import os

import brain

from cmdparse import Command

log = logging.getLogger("hal")

class InitCommand(Command):
    def __init__(self):
        Command.__init__(self, "init", summary="Initialize a new brain")

        self.add_option("", "--force", action="store_true") 
        self.add_option("", "--order", type="int", default=5)

    def run(self, options, args):
        filename = "hal.brain"

        if os.path.exists(filename):
            if options.force:
                os.remove(filename)
            else:
                log.error("%s already exists!", filename)
                return

        b = brain.Brain(filename)
        b.init(order)

class CloneCommand(Command):
    def __init__(self):
        Command.__init__(self, "clone", summary="Clone a MegaHAL brain")

    def run(self, options, args):
        if len(args) != 1:
            log.error("usage: clone <MegaHAL brain>")
            return

        if os.path.exists("hal.brain"):
            log.error("hal.brain already exists")
            return

        megahal_brain = args[0]

        b = brain.Brain("hal.brain")
        b.init()
        b.clone(megahal_brain)


import logging
import os

from brain import Brain

from cmdparse import Command

log = logging.getLogger("hal")

class InitCommand(Command):
    def __init__(self):
        Command.__init__(self, "init", summary="Initialize a new brain")

        self.add_option("", "--force", action="store_true") 
        self.add_option("", "--order", type="int", default=5)

    def run(self, options, args):
        filename = "hal.brain"

        if os.path.exists(filename):
            if options.force:
                os.remove(filename)
            else:
                log.error("%s already exists!", filename)
                return

        Brain.init(filename, options.order)

class CloneCommand(Command):
    def __init__(self):
        Command.__init__(self, "clone", summary="Clone a MegaHAL brain")

    def run(self, options, args):
        if len(args) != 1:
            log.error("usage: clone <MegaHAL brain>")
            return

        if os.path.exists("hal.brain"):
            log.error("hal.brain already exists")
            return

        megahal_brain = args[0]

        Brain.init("hal.brain")
        b.clone(megahal_brain)

Update to use the static Brain.init()
Update to use the static Brain.init()

  import logging
  import os
  
- import brain
+ from brain import Brain
  
  from cmdparse import Command
  
  log = logging.getLogger("hal")
  
  class InitCommand(Command):
      def __init__(self):
          Command.__init__(self, "init", summary="Initialize a new brain")
  
          self.add_option("", "--force", action="store_true") 
          self.add_option("", "--order", type="int", default=5)
  
      def run(self, options, args):
          filename = "hal.brain"
  
          if os.path.exists(filename):
              if options.force:
                  os.remove(filename)
              else:
                  log.error("%s already exists!", filename)
                  return
  
+         Brain.init(filename, options.order)
-         b = brain.Brain(filename)
-         b.init(order)
  
  class CloneCommand(Command):
      def __init__(self):
          Command.__init__(self, "clone", summary="Clone a MegaHAL brain")
  
      def run(self, options, args):
          if len(args) != 1:
              log.error("usage: clone <MegaHAL brain>")
              return
  
          if os.path.exists("hal.brain"):
              log.error("hal.brain already exists")
              return
  
          megahal_brain = args[0]
  
-         b = brain.Brain("hal.brain")
+         Brain.init("hal.brain")
-         b.init()
          b.clone(megahal_brain)
  
- 
Update to use the static Brain.init()
## Code Before:
import logging
import os

import brain

from cmdparse import Command

log = logging.getLogger("hal")

class InitCommand(Command):
    def __init__(self):
        Command.__init__(self, "init", summary="Initialize a new brain")

        self.add_option("", "--force", action="store_true") 
        self.add_option("", "--order", type="int", default=5)

    def run(self, options, args):
        filename = "hal.brain"

        if os.path.exists(filename):
            if options.force:
                os.remove(filename)
            else:
                log.error("%s already exists!", filename)
                return

        b = brain.Brain(filename)
        b.init(order)

class CloneCommand(Command):
    def __init__(self):
        Command.__init__(self, "clone", summary="Clone a MegaHAL brain")

    def run(self, options, args):
        if len(args) != 1:
            log.error("usage: clone <MegaHAL brain>")
            return

        if os.path.exists("hal.brain"):
            log.error("hal.brain already exists")
            return

        megahal_brain = args[0]

        b = brain.Brain("hal.brain")
        b.init()
        b.clone(megahal_brain)


## Instruction:
Update to use the static Brain.init()
## Code After:
import logging
import os

from brain import Brain

from cmdparse import Command

log = logging.getLogger("hal")

class InitCommand(Command):
    def __init__(self):
        Command.__init__(self, "init", summary="Initialize a new brain")

        self.add_option("", "--force", action="store_true") 
        self.add_option("", "--order", type="int", default=5)

    def run(self, options, args):
        filename = "hal.brain"

        if os.path.exists(filename):
            if options.force:
                os.remove(filename)
            else:
                log.error("%s already exists!", filename)
                return

        Brain.init(filename, options.order)

class CloneCommand(Command):
    def __init__(self):
        Command.__init__(self, "clone", summary="Clone a MegaHAL brain")

    def run(self, options, args):
        if len(args) != 1:
            log.error("usage: clone <MegaHAL brain>")
            return

        if os.path.exists("hal.brain"):
            log.error("hal.brain already exists")
            return

        megahal_brain = args[0]

        Brain.init("hal.brain")
        b.clone(megahal_brain)
