Beispiel #1
0
def main(): # pragma: no cover
  """Entry point for scripts."""
  # Always add anvil/.. to the path
  sys.path.insert(1, util.get_anvil_path())

  # TODO(benvanik): if a command is specified try loading it first - may be
  #     able to avoid searching all commands
  search_paths = [os.path.join(util.get_anvil_path(), 'commands')]
  # TODO(benvanik): look for a .anvilrc, load it to find
  # - extra command search paths
  # - extra rule search paths
  # Also check to see if it was specified in args?

  # Find all commands
  commands = discover_commands(search_paths)

  # Run auto-completion logic
  if 'ANVIL_AUTO_COMPLETE' in os.environ:
    match_str = autocomplete(
        words=os.environ['COMP_WORDS'].split(' ')[1:],
        cword=int(os.environ['COMP_CWORD']) - 1,
        cwd=os.getcwd(),
        commands=commands)
    if match_str and len(match_str):
      print match_str
    sys.exit(1)

  try:
    if len(sys.argv) < 2:
      raise ValueError('No command given')
    command_name = sys.argv[1]
    if not commands.has_key(command_name):
      raise ValueError('Command "%s" not found' % (command_name))

    command = commands[command_name]
    return_code = run_command(command=command,
                              args=sys.argv[2:],
                              cwd=os.getcwd())
  except ValueError:
    print usage(commands)
    return_code = 1
  except Exception as e:
    #print e
    raise
    return_code = 1
  sys.exit(return_code)
Beispiel #2
0
    def setUp(self):
        super(FixtureTestCase, self).setUp()

        # Root output path
        self.temp_path = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, self.temp_path)
        self.root_path = self.temp_path

        # Copy fixture files
        if self.fixture:
            self.root_path = os.path.join(self.root_path, self.fixture)
            build_path = util.get_anvil_path()
            if not build_path:
                raise Error('Unable to find build path')
            fixture_path = os.path.join(build_path, '..', 'test', 'fixtures',
                                        self.fixture)
            target_path = os.path.join(self.temp_path, self.fixture)
            shutil.copytree(fixture_path, target_path)
Beispiel #3
0
  def setUp(self):
    super(FixtureTestCase, self).setUp()

    # Root output path
    self.temp_path = tempfile.mkdtemp()
    self.addCleanup(shutil.rmtree, self.temp_path)
    self.root_path = self.temp_path

    # Copy fixture files
    if self.fixture:
      self.root_path = os.path.join(self.root_path, self.fixture)
      build_path = util.get_anvil_path()
      if not build_path:
        raise Error('Unable to find build path')
      fixture_path = os.path.join(
          build_path, '..', 'test', 'fixtures', self.fixture)
      target_path = os.path.join(self.temp_path, self.fixture)
      shutil.copytree(fixture_path, target_path)
Beispiel #4
0
    if match_str and len(match_str):
      print match_str
    sys.exit(1)

  try:
    if len(sys.argv) < 2:
      raise ValueError('No command given')
    command_name = sys.argv[1]
    if not commands.has_key(command_name):
      raise ValueError('Command "%s" not found' % (command_name))

    command = commands[command_name]
    return_code = run_command(command=command,
                              args=sys.argv[2:],
                              cwd=os.getcwd())
  except ValueError:
    print usage(commands)
    return_code = 1
  except Exception as e:
    #print e
    raise
    return_code = 1
  sys.exit(return_code)


if __name__ == '__main__':
  import anvil.manage
  # Always add anvil/.. to the path
  sys.path.insert(1, os.path.join(util.get_anvil_path(), '..'))
  anvil.manage.main()