* [PATCH v2 1/3] devel: make printmimestructure py3 compatible
@ 2018-06-12 21:21 Daniel Kahn Gillmor
2018-06-12 21:21 ` [PATCH v2 2/3] minor cleanup to printmimestructure Daniel Kahn Gillmor
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Daniel Kahn Gillmor @ 2018-06-12 21:21 UTC (permalink / raw)
To: Notmuch Mail
Make printmimestructure work in python3 as well as python2.
PEP 394 suggests that python scripts that work with both python2 and
python3 should have a #!/usr/bin/python command line, so do that too.
---
devel/printmimestructure | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/devel/printmimestructure b/devel/printmimestructure
index 34d12930..a5fc83e7 100755
--- a/devel/printmimestructure
+++ b/devel/printmimestructure
@@ -19,6 +19,8 @@
# If you want to number the parts, i suggest piping the output through
# something like "cat -n"
+from __future__ import print_function
+
import email
import sys
@@ -34,7 +36,7 @@ def test(z, prefix=''):
if d[0] in [ 'attachment', 'inline' ]:
disposition = ' ' + d[0]
if (z.is_multipart()):
- print prefix + '┬╴' + z.get_content_type() + cset + disposition + fname, z.as_string().__len__().__str__() + ' bytes'
+ print(prefix + '┬╴' + z.get_content_type() + cset + disposition + fname, z.as_string().__len__().__str__() + ' bytes')
if prefix.endswith('└'):
prefix = prefix.rpartition('└')[0] + ' '
if prefix.endswith('├'):
@@ -47,6 +49,6 @@ def test(z, prefix=''):
test(parts[i], prefix + '└')
# FIXME: show epilogue?
else:
- print prefix + '─╴'+ z.get_content_type() + cset + disposition + fname, z.get_payload().__len__().__str__(), 'bytes'
+ print(prefix + '─╴'+ z.get_content_type() + cset + disposition + fname, z.get_payload().__len__().__str__(), 'bytes')
test(email.message_from_file(sys.stdin), '└')
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] minor cleanup to printmimestructure
2018-06-12 21:21 [PATCH v2 1/3] devel: make printmimestructure py3 compatible Daniel Kahn Gillmor
@ 2018-06-12 21:21 ` Daniel Kahn Gillmor
2018-06-12 21:21 ` [PATCH v2 3/3] use #!/usr/bin/env python consistently Daniel Kahn Gillmor
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Daniel Kahn Gillmor @ 2018-06-12 21:21 UTC (permalink / raw)
To: Notmuch Mail
From: Jameson Graef Rollins <jrollins@finestructure.net>
make the source slightly easier to read. no functional change.
---
devel/printmimestructure | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/devel/printmimestructure b/devel/printmimestructure
index a5fc83e7..70e0a5c0 100755
--- a/devel/printmimestructure
+++ b/devel/printmimestructure
@@ -24,7 +24,7 @@ from __future__ import print_function
import email
import sys
-def test(z, prefix=''):
+def print_part(z, prefix):
fname = '' if z.get_filename() is None else ' [' + z.get_filename() + ']'
cset = '' if z.get_charset() is None else ' (' + z.get_charset() + ')'
disp = z.get_params(None, header='Content-Disposition')
@@ -35,8 +35,23 @@ def test(z, prefix=''):
for d in disp:
if d[0] in [ 'attachment', 'inline' ]:
disposition = ' ' + d[0]
+ if z.is_multipart():
+ nbytes = len(z.as_string())
+ else:
+ nbytes = len(z.get_payload())
+
+ print('{}{}{}{}{} {:d} bytes'.format(
+ prefix,
+ z.get_content_type(),
+ cset,
+ disposition,
+ fname,
+ nbytes,
+ ))
+
+def test(z, prefix=''):
if (z.is_multipart()):
- print(prefix + '┬╴' + z.get_content_type() + cset + disposition + fname, z.as_string().__len__().__str__() + ' bytes')
+ print_part(z, prefix+'┬╴')
if prefix.endswith('└'):
prefix = prefix.rpartition('└')[0] + ' '
if prefix.endswith('├'):
@@ -49,6 +64,6 @@ def test(z, prefix=''):
test(parts[i], prefix + '└')
# FIXME: show epilogue?
else:
- print(prefix + '─╴'+ z.get_content_type() + cset + disposition + fname, z.get_payload().__len__().__str__(), 'bytes')
+ print_part(z, prefix+'─╴')
test(email.message_from_file(sys.stdin), '└')
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] use #!/usr/bin/env python consistently
2018-06-12 21:21 [PATCH v2 1/3] devel: make printmimestructure py3 compatible Daniel Kahn Gillmor
2018-06-12 21:21 ` [PATCH v2 2/3] minor cleanup to printmimestructure Daniel Kahn Gillmor
@ 2018-06-12 21:21 ` Daniel Kahn Gillmor
2018-06-12 21:32 ` Tomi Ollila
2018-06-12 22:55 ` [PATCH v2 1/3] devel: make printmimestructure py3 compatible David Bremner
2018-06-14 23:46 ` David Bremner
3 siblings, 1 reply; 6+ messages in thread
From: Daniel Kahn Gillmor @ 2018-06-12 21:21 UTC (permalink / raw)
To: Notmuch Mail
---
devel/nmbug/notmuch-report | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/devel/nmbug/notmuch-report b/devel/nmbug/notmuch-report
index 5789c5f4..eaceb2ce 100755
--- a/devel/nmbug/notmuch-report
+++ b/devel/nmbug/notmuch-report
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# Copyright (c) 2011-2012 David Bremner <david@tethera.net>
#
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/3] devel: make printmimestructure py3 compatible
2018-06-12 21:21 [PATCH v2 1/3] devel: make printmimestructure py3 compatible Daniel Kahn Gillmor
2018-06-12 21:21 ` [PATCH v2 2/3] minor cleanup to printmimestructure Daniel Kahn Gillmor
2018-06-12 21:21 ` [PATCH v2 3/3] use #!/usr/bin/env python consistently Daniel Kahn Gillmor
@ 2018-06-12 22:55 ` David Bremner
2018-06-14 23:46 ` David Bremner
3 siblings, 0 replies; 6+ messages in thread
From: David Bremner @ 2018-06-12 22:55 UTC (permalink / raw)
To: Daniel Kahn Gillmor, Notmuch Mail
Daniel Kahn Gillmor <dkg@fifthhorseman.net> writes:
> Make printmimestructure work in python3 as well as python2.
>
> PEP 394 suggests that python scripts that work with both python2 and
> python3 should have a #!/usr/bin/python command line, so do that too.
I think the second paragraph is vestigal.
d
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/3] devel: make printmimestructure py3 compatible
2018-06-12 21:21 [PATCH v2 1/3] devel: make printmimestructure py3 compatible Daniel Kahn Gillmor
` (2 preceding siblings ...)
2018-06-12 22:55 ` [PATCH v2 1/3] devel: make printmimestructure py3 compatible David Bremner
@ 2018-06-14 23:46 ` David Bremner
3 siblings, 0 replies; 6+ messages in thread
From: David Bremner @ 2018-06-14 23:46 UTC (permalink / raw)
To: Daniel Kahn Gillmor, Notmuch Mail
Daniel Kahn Gillmor <dkg@fifthhorseman.net> writes:
> Make printmimestructure work in python3 as well as python2.
>
> PEP 394 suggests that python scripts that work with both python2 and
> python3 should have a #!/usr/bin/python command line, so do that too.
Series pushed, less that (no longer operative) paragraph ^
d
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-06-14 23:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-12 21:21 [PATCH v2 1/3] devel: make printmimestructure py3 compatible Daniel Kahn Gillmor
2018-06-12 21:21 ` [PATCH v2 2/3] minor cleanup to printmimestructure Daniel Kahn Gillmor
2018-06-12 21:21 ` [PATCH v2 3/3] use #!/usr/bin/env python consistently Daniel Kahn Gillmor
2018-06-12 21:32 ` Tomi Ollila
2018-06-12 22:55 ` [PATCH v2 1/3] devel: make printmimestructure py3 compatible David Bremner
2018-06-14 23:46 ` David Bremner
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).