def __send_message(msg_type, tmpl, options, *args): """Message sending dispatcher. """ domain = options.domain or config.get('stgit.domain') if domain: if sys.version_info < (3, 2): raise CmdException("Setting domain requires Python version 3.2+") msg_id = email.utils.make_msgid('stgit', domain=domain) else: msg_id = email.utils.make_msgid('stgit') if msg_type == 'cover': assert len(args) == 1, 'too many args for msg_type == "cover"' patches = args[0] msg = __build_cover(tmpl, msg_id, options, patches) outstr = 'the cover message' elif msg_type == 'patch': patch, patch_nr, total_nr, ref_id = args msg = __build_message(tmpl, msg_id, options, patch, patch_nr, total_nr, ref_id) outstr = 'patch "%s"' % patch else: raise AssertionError('invalid msg_type: %s' % msg_type) # pragma: no cover if hasattr(msg, 'as_bytes'): msg_bytes = msg.as_bytes(options.mbox) else: msg_bytes = msg.as_string(options.mbox) # Python 3.3 only has Message.as_string(). We encode it back to bytes # and hope for the best. if isinstance(msg_bytes, text): msg_bytes = msg_bytes.encode('utf-8') if options.mbox: out.stdout_bytes(msg_bytes + b'\n') return msg_id if not options.git: from_addr, to_addrs = __parse_addresses(msg) out.start('Sending ' + outstr) smtpserver = options.smtp_server or config.get('stgit.smtpserver') if options.git: __send_message_git(msg_bytes, msg['From'], options) elif smtpserver.startswith('/'): # Use the sendmail tool __send_message_sendmail(smtpserver, msg_bytes) else: # Use the SMTP server (we have host and port information) __send_message_smtp(smtpserver, from_addr, to_addrs, msg_bytes, options) # give recipients a chance of receiving related patches in correct order if msg_type == 'cover' or (msg_type == 'patch' and patch_nr < total_nr): sleep = options.sleep or config.getint('stgit.smtpdelay') time.sleep(sleep) if not options.git: out.done() return msg_id
def pager(msg): if any([ not hasattr(sys.stdin, 'isatty'), not hasattr(sys.stdout, 'isatty'), not sys.stdin.isatty(), not sys.stdout.isatty() ]): return out.stdout_bytes(msg) pager = _choose_pager() if pager: return _run_pager(pager, msg) else: return out.stdout_bytes(msg)
def __send_message(msg_type, tmpl, options, *args): """Message sending dispatcher. """ msg_id = email.utils.make_msgid('stgit', domain=options.domain or config.get('stgit.domain')) if msg_type == 'cover': assert len(args) == 1, 'too many args for msg_type == "cover"' patches = args[0] msg = __build_cover(tmpl, msg_id, options, patches) outstr = 'the cover message' elif msg_type == 'patch': patch, patch_nr, total_nr, ref_id = args msg = __build_message(tmpl, msg_id, options, patch, patch_nr, total_nr, ref_id) outstr = 'patch "%s"' % patch else: raise AssertionError('invalid msg_type: %s' % msg_type) # pragma: no cover msg_bytes = msg.as_bytes(options.mbox) if options.mbox: out.stdout_bytes(msg_bytes + b'\n') return msg_id if not options.git: from_addr, to_addrs = __parse_addresses(msg) out.start('Sending ' + outstr) smtpserver = options.smtp_server or config.get('stgit.smtpserver') if options.git: __send_message_git(msg_bytes, msg['From'], options) elif smtpserver.startswith('/'): # Use the sendmail tool __send_message_sendmail(smtpserver, msg_bytes) else: # Use the SMTP server (we have host and port information) __send_message_smtp(smtpserver, from_addr, to_addrs, msg_bytes, options) # give recipients a chance of receiving related patches in correct order if msg_type == 'cover' or (msg_type == 'patch' and patch_nr < total_nr): sleep = options.sleep or config.getint('stgit.smtpdelay') time.sleep(sleep) if not options.git: out.done() return msg_id
def __send_message(type, tmpl, options, *args): """Message sending dispatcher. """ (build, outstr) = { 'cover': (__build_cover, 'the cover message'), 'patch': (__build_message, 'patch "%s"' % args[0]), }[type] if type == 'patch': (patch_nr, total_nr) = (args[1], args[2]) msg_id = email.utils.make_msgid('stgit') msg = build(tmpl, msg_id, options, *args) if hasattr(msg, 'as_bytes'): msg_bytes = msg.as_bytes(options.mbox) else: msg_bytes = msg.as_string(options.mbox) # Python 3.3 only has Message.as_string(). We encode it back to bytes # and hope for the best. if isinstance(msg_bytes, text): msg_bytes = msg_bytes.encode('utf-8') if options.mbox: out.stdout_bytes(msg_bytes + b'\n') return msg_id if not options.git: from_addr, to_addrs = __parse_addresses(msg) out.start('Sending ' + outstr) smtpserver = options.smtp_server or config.get('stgit.smtpserver') if options.git: __send_message_git(msg_bytes, msg['From'], options) elif smtpserver.startswith('/'): # Use the sendmail tool __send_message_sendmail(smtpserver, msg_bytes) else: # Use the SMTP server (we have host and port information) __send_message_smtp(smtpserver, from_addr, to_addrs, msg_bytes, options) # give recipients a chance of receiving related patches in correct order if type == 'cover' or (type == 'patch' and patch_nr < total_nr): sleep = options.sleep or config.getint('stgit.smtpdelay') time.sleep(sleep) if not options.git: out.done() return msg_id
def func(parser, options, args): """Show the files modified by a patch (or the current patch) """ if options.bare and options.stat: raise CmdException('Cannot specify both --bare and --stat') repository = directory.repository if len(args) == 0: stack = repository.current_stack commit = stack.top elif len(args) == 1: branch, name = parse_rev(args[0]) stack = repository.get_stack(branch) if not stack.patches.exists(name): raise CmdException('%s: Unknown patch name' % name) commit = stack.patches.get(name).commit else: parser.error('incorrect number of arguments') if options.stat: cmd = ['git', 'diff-tree', '--stat', '--summary', '--no-commit-id'] cmd.extend(options.diff_flags) cmd.extend(color_diff_flags()) cmd.append(commit.sha1) out.stdout_bytes(repository.run(cmd).decoding(None).raw_output()) else: used = set() for dt in repository.diff_tree_files( commit.data.parent.data.tree, commit.data.tree ): _, _, _, _, status, oldname, newname = dt for filename in [oldname, newname]: if filename in used: continue else: used.add(filename) if options.bare: out.stdout(filename) else: out.stdout('%s %s' % (status, filename))
def w(s): out.stdout_bytes(s)
def pager(msg): pager = _choose_pager() if not sys.stdin.isatty() or not sys.stdout.isatty() or not pager: return out.stdout_bytes(msg) else: return _run_pager(pager, msg)