Exemplo n.º 1
0
 def test_write_through(self):
     v = load(StringIO.StringIO(self.s1))
     d = v.pop(0)
     d.apply('b', 2)
     s2 = StringIO.StringIO()
     dump(d, s2)
     s2_str = s2.getvalue()
     v2 = load(StringIO.StringIO(s2_str))
     assert d.real == v2, (v2.real, d.real)
     assert d == v2
Exemplo n.º 2
0
def main():
    """JIRA-Yaml Writer.

Usage:
  jywriter [options] <input>
  jywriter [options] <input> <output>

Options:
  -U --update   Update all the known tickets with Status.
  -P --purge    Remove all completed items
  -h --help     Show this screen.
  -t --test     Use a mock instead of connecting to JIRA.
  --freemind    Output to freemind
    """
    arguments = docopt(main.__doc__)

    if arguments.get('--test'):
        _connect = mock_connect
        arguments['<output>'] = "/dev/stdout"
    else:
        _connect = connect

    if not arguments.get("<output>"):
        arguments['<output>'] = arguments['<input>']

    if arguments['--freemind']:
        from jy.freemind import Writer
        w = Writer(open(arguments.get('<output>', '/dev/stdout'), 'w'))
        items = load(open(arguments["<input>"]))
        w.doc({arguments["<input>"]: items})
        return

    conf = None
    defaults = os.path.expanduser("~/.jy")
    if os.path.exists(defaults):
        conf = load(open(defaults))

    jira = connect(conf)
    items = load(open(arguments["<input>"]))
    context = Context(jira)

    if conf:
        NewManifest(context)(conf)
    try:
        if arguments.get("--update"):
            UpdateIssues(context, arguments.get('--purge'))(items)
        else:
            ApplyTransformers(context)(items)
    finally:
        with open(arguments['<output>'], "w") as f:
            dump(items, f, default_flow_style=False)
Exemplo n.º 3
0
def main():
    parser = OptionParser()
    parser.add_option("-t", "--test",
                      action="store_true", dest="test", default=False,
                      help="test mode")
    parser.add_option("-O", "--output",
                      dest="output", default=None,
                      help="output file", metavar="OUTFILE")

    (options, args) = parser.parse_args()

    if options.test:
        from mock import Mock
        jira = Mock(spec=GreenHopper)
        jira.search_issues.return_value = [Mock(), Mock()]

        def create_issue(**kwargs):
            m = Mock()
            m.key = kwargs
            return m
        jira.create_issue.side_effect = create_issue
        options.output = "/dev/stdout"
    else:
        jira = connect()
    infile = args[0]
    outfile = options.output or infile

    items = load(open(infile))

    context = Context(jira)

    defaults = os.path.expanduser("~/.jy")
    if os.path.exists(defaults):
        def_ = load(open(defaults))
        NewManifest(context)(def_)
    try:
        ApplyTransformers(context)(items)
    finally:
        with open(outfile, "w") as f:
            dump(items, f, default_flow_style=False)