From: Paolo Bonzini <pbonzini@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>,
Yonggang Luo <luoyonggang@gmail.com>
Cc: "QEMU Trivial" <qemu-trivial@nongnu.org>,
"Thomas Huth" <thuth@redhat.com>,
"QEMU Developers" <qemu-devel@nongnu.org>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: Re: [PATCH v2] scripts: Convert qemu-version.sh to qemu-version.py
Date: Tue, 6 Oct 2020 09:42:08 +0200 [thread overview]
Message-ID: <7f6f412b-03f8-b8f3-9708-0080277999a6@redhat.com> (raw)
In-Reply-To: <CAFEAcA95r2FZibphrO0N_rckWOKigM_d80Qi0grtpWWzN3d19A@mail.gmail.com>
On 05/10/20 21:22, Peter Maydell wrote:
>> +def main(args):
>> + if len(args) <= 3:
>> + sys.exit(0)
>> +
>> + dir = args[1]
>> + pkgversion = args[2]
>> + version = args[3]
In addition to what Peter pointed out, all these lines can be changed to
def main(dir, pkgversion, version, *unused):
and below
if __name__ == "__main__":
main(*sys.argv)
>> + pc = subprocess.run(['git', 'describe', '--match', "'v*'", '--dirty', '--always'],
>> + stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, cwd=dir)
>> + if pc.returncode == 0:
>> + pkgversion = pc.stdout.decode('utf8').strip()
>> + fullversion = version
>> + if len(pkgversion) > 0:
Just "if pkgversion:" please.
>> + fullversion = "{} ({})".format(version, pkgversion)
>> +
>> + version_header = '''#define QEMU_PKGVERSION "{}"
>> +#define QEMU_FULL_VERSION "{}"'''.format(pkgversion, fullversion)
>> + sys.stdout.buffer.write(version_header.encode('utf8'))
No need to use buffer and encode, just
print('#define QEMU_PKGVERSION "%s"' % pkgversion)
print('#define QEMU_FULLVERSION "%s"' % fullversion)
It is still a bit more clunky than a shell script, but at least not as much.
Paolo
prev parent reply other threads:[~2020-10-06 8:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-05 17:21 [PATCH v2] scripts: Convert qemu-version.sh to qemu-version.py Yonggang Luo
2020-10-05 18:10 ` Philippe Mathieu-Daudé
2020-10-05 18:16 ` 罗勇刚(Yonggang Luo)
2020-10-05 19:22 ` Peter Maydell
2020-10-05 19:55 ` 罗勇刚(Yonggang Luo)
2020-10-06 7:42 ` Paolo Bonzini [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7f6f412b-03f8-b8f3-9708-0080277999a6@redhat.com \
--to=pbonzini@redhat.com \
--cc=f4bug@amsat.org \
--cc=luoyonggang@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).