Esempio n. 1
0
def tricks_generate_yaml(args):
    """
    Subcommand to generate Yaml configuration for tricks named on the command
    line.

    :param args:
        Command line argument options.
    """
    python_paths = path_split(args.python_path)
    add_to_sys_path(python_paths)
    output = StringIO()

    for trick_path in args.trick_paths:
        TrickClass = load_class(trick_path)
        output.write(TrickClass.generate_yaml())

    content = output.getvalue()
    output.close()

    header = yaml.dump({CONFIG_KEY_PYTHON_PATH: python_paths})
    header += "%s:\n" % CONFIG_KEY_TRICKS
    if args.append_to_file is None:
        # Output to standard output.
        if not args.append_only:
            content = header + content
        sys.stdout.write(content)
    else:
        if not os.path.exists(args.append_to_file):
            content = header + content
        with open(args.append_to_file, 'ab') as output:
            output.write(content)
Esempio n. 2
0
def schedule_tricks(observer, tricks, pathname, recursive):
    for trick in tricks:
        for name, value in list(trick.items()):
            TrickClass = load_class(name)
            handler = TrickClass(**value)
            trick_pathname = getattr(handler, 'source_directory', None) or pathname
            observer.schedule(handler, trick_pathname, recursive)
Esempio n. 3
0
def tricks_generate_yaml(args):
  """
  Subcommand to generate Yaml configuration for tricks named on the command
  line.

  :param args:
      Command line argument options.
  """
  python_paths = path_split(args.python_path)
  add_to_sys_path(python_paths)
  output = StringIO()

  for trick_path in args.trick_paths:
    TrickClass = load_class(trick_path)
    output.write(TrickClass.generate_yaml())

  content = output.getvalue()
  output.close()

  header = yaml.dump({CONFIG_KEY_PYTHON_PATH: python_paths})
  header += "%s:\n" % CONFIG_KEY_TRICKS
  if args.append_to_file is None:
    # Output to standard output.
    if not args.append_only:
      content = header + content
    sys.stdout.write(content)
  else:
    if not os.path.exists(args.append_to_file):
      content = header + content
    output = open(args.append_to_file, 'ab')
    output.write(content)
    output.close()
Esempio n. 4
0
def schedule_tricks(observer, tricks, pathname, recursive):
    for trick in tricks:
        for name, value in list(trick.items()):
            TrickClass = load_class(name)
            handler = TrickClass(**value)
            trick_pathname = getattr(handler, 'source_directory', None) or pathname
            observer.schedule(handler, trick_pathname, recursive)
Esempio n. 5
0
def schedule_tricks(observer, tricks, pathname, recursive):
    """
    Schedules tricks with the specified observer and for the given watch
    path.

    :param observer:
        The observer thread into which to schedule the trick and watch.
    :param tricks:
        A list of tricks.
    :param pathname:
        A path name which should be watched.
    :param recursive:
        ``True`` if recursive; ``False`` otherwise.
    """
    for trick in tricks:
        for name, value in trick.items():
            TrickClass = load_class(name)
            handler = TrickClass(**value)
            observer.schedule(handler, pathname, recursive)
Esempio n. 6
0
def schedule_tricks(observer, tricks, pathname, recursive):
    """
    Schedules tricks with the specified observer and for the given watch
    path.

    :param observer:
        The observer thread into which to schedule the trick and watch.
    :param tricks:
        A list of tricks.
    :param pathname:
        A path name which should be watched.
    :param recursive:
        ``True`` if recursive; ``False`` otherwise.
    """
    for trick in tricks:
        for name, value in list(trick.items()):
            TrickClass = load_class(name)
            handler = TrickClass(**value)
            trick_pathname = getattr(handler, 'source_directory', None) or pathname
            observer.schedule(handler, trick_pathname, recursive)
Esempio n. 7
0
def tricks_generate_yaml(args):
    python_paths = path_split(args.python_path)
    add_to_sys_path(python_paths)
    output = StringIO()
    for trick_path in args.trick_paths:
        TrickClass = load_class(trick_path)
        output.write(TrickClass.generate_yaml())

    content = output.getvalue()
    output.close()
    header = yaml.dump({CONFIG_KEY_PYTHON_PATH: python_paths})
    header += '%s:\n' % CONFIG_KEY_TRICKS
    if args.append_to_file is None:
        if not args.append_only:
            content = header + content
        sys.stdout.write(content)
    else:
        if not os.path.exists(args.append_to_file):
            content = header + content
        output = open(args.append_to_file, 'ab')
        output.write(content)
        output.close()
Esempio n. 8
0
def tricks_generate_yaml(args):
    python_paths = path_split(args.python_path)
    add_to_sys_path(python_paths)
    output = StringIO()
    for trick_path in args.trick_paths:
        TrickClass = load_class(trick_path)
        output.write(TrickClass.generate_yaml())

    content = output.getvalue()
    output.close()
    header = yaml.dump({CONFIG_KEY_PYTHON_PATH: python_paths})
    header += '%s:\n' % CONFIG_KEY_TRICKS
    if args.append_to_file is None:
        if not args.append_only:
            content = header + content
        sys.stdout.write(content)
    else:
        if not os.path.exists(args.append_to_file):
            content = header + content
        output = open(args.append_to_file, 'ab')
        output.write(content)
        output.close()