From cfc689dcb00f3b81e857c8fbd21e4599443ceeff Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Thu, 20 Feb 2020 14:01:25 -0800 Subject: Reinstate util/chargen Cr50 related utilities should be coming from the cr50_stab branch of the EC tree. This patch brings back the ToT version of the util/chargen script which was previously dropped. BRANCH=cr50, cr50-mp BUG=b:149350081 TEST=with the rest of the patches applied installed chargen is taken from platform/cr50 Change-Id: I407c2e8676b28ecc894a59e977feb474f89e880a Signed-off-by: Vadim Bendebury Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2067163 Reviewed-by: Mary Ruthven --- util/chargen | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 util/chargen diff --git a/util/chargen b/util/chargen new file mode 100644 index 0000000000..42c40f13e4 --- /dev/null +++ b/util/chargen @@ -0,0 +1,69 @@ +#!/usr/bin/env python2 +# Copyright 2019 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import sys + +def chargen(modulo, max_chars): + """Generate a stream of characters on the console. + + The stream is an ever incrementing pattern of characters from the + following set: 0..9A..Za..z. + + Args: + modulo: an int, restart the pattern every modulo characters, if + modulo is non zero + max_chars: an int, stop printing after this number of characters if non + zero, if zero - print indefinitely + """ + + base = '0' + c = base + counter = 0 + while True: + sys.stdout.write(c) + counter = counter + 1 + + if (max_chars != 0) and (counter == max_chars): + sys.stdout.write('\n') + return + + if modulo and ((counter % modulo) == 0): + c = base + continue + + if c == 'z': + c = base + elif c == 'Z': + c = 'a' + elif c == '9': + c = 'A' + else: + c = '%c' % (ord(c) + 1) + + +def main(args): + '''Process command line arguments and invoke chargen if args are valid''' + + modulo = 0 + max_chars = 0 + + try: + if len(args) > 0: + modulo = int(args[0]) + if len(args) > 1: + max_chars = int(args[1]) + except ValueError: + sys.stderr.write('usage %s:' + "['seq_length' ['max_chars']]\n") + sys.exit(1) + + try: + chargen(modulo, max_chars) + except KeyboardInterrupt: + print + +if __name__ == '__main__': + main(sys.argv[1:]) + sys.exit(0) -- cgit v1.2.1