[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Git][ftp-team/dak][master] 2 commits: tools/logs.py: switch to Python 3



Title: GitLab

Ansgar pushed to branch master at Debian FTP Team / dak

Commits:

1 changed file:

Changes:

  • tools/logs.py
    1
    -#!/usr/bin/python
    
    1
    +#!/usr/bin/python3
    
    2 2
     # (c) 2008 Thomas Viehmann
    
    3 3
     # Free software licensed under the GPL version 2 or later
    
    4 4
     
    
    5
    -
    
    6
    -from __future__ import print_function
    
    7
    -
    
    8 5
     import os
    
    9 6
     import re
    
    10 7
     import datetime
    
    ... ... @@ -55,7 +52,7 @@ if args:
    55 52
             m = LINE.match(l)
    
    56 53
             if not m:
    
    57 54
                 raise Exception("woops '%s'" % l)
    
    58
    -        g = map(lambda x: (not x.isdigit() and x) or int(x), m.groups())
    
    55
    +        g = [int(x) if x.isdigit() else x for x in m.groups()]
    
    59 56
             dt = datetime.datetime(*g[:6])
    
    60 57
             if olddt != dt:
    
    61 58
                 oldsecs = 0
    
    ... ... @@ -71,16 +68,13 @@ if args:
    71 68
                 kl.append(k)
    
    72 69
     
    
    73 70
     if (wantkeys - ks):
    
    74
    -    print("warning, requested keys not found in any log: " + ' '.join(wantkeys - ks), file=sys.stderr)
    
    71
    +    print("warning, requested keys not found in any log:", *(wantkeys - ks), file=sys.stderr)
    
    75 72
     
    
    76
    -datakeys = d.keys()
    
    77
    -datakeys.sort()
    
    73
    +datakeys = sorted(d.keys())
    
    78 74
     
    
    79
    -f = open(CACHE_FILE + ".tmp", "w")
    
    80
    -for dk in datakeys:
    
    81
    -    print(dk + '\t' + '\t'.join(
    
    82
    -        ["%s:%s" % (k, str(d[dk][k])) for k in kl if k in d[dk]]), file=f)
    
    83
    -f.close()
    
    75
    +with open(CACHE_FILE + ".tmp", "w") as f:
    
    76
    +    for dk in datakeys:
    
    77
    +        print(dk, *("%s:%s" % (k, str(d[dk][k])) for k in kl if k in d[dk]), sep='\t', file=f)
    
    84 78
     os.rename(CACHE_FILE + ".tmp", CACHE_FILE)
    
    85 79
     datakeys = datakeys[-ITEMS_TO_KEEP:]
    
    86 80
     
    
    ... ... @@ -88,15 +82,14 @@ datakeys = datakeys[-ITEMS_TO_KEEP:]
    88 82
     def dump_file(outfn, keystolist, showothers):
    
    89 83
         showothers = (showothers and 1) or 0
    
    90 84
         # careful, outfn is NOT ESCAPED
    
    91
    -    f = tempfile.NamedTemporaryFile()
    
    85
    +    f = tempfile.NamedTemporaryFile("w+t")
    
    92 86
         otherkeys = ks - set(keystolist)
    
    93 87
         print('\t'.join(keystolist + showothers * ['other']), file=f)
    
    94 88
         for k in datakeys:
    
    95 89
             v = d[k]
    
    96
    -        others = sum(map(lambda x: v.get(x, 0), otherkeys))
    
    97
    -        print(k + '\t' + '\t'.join(map(lambda x: str(v.get(x, 0)), keystolist) + showothers * [str(others)]), file=f)
    
    90
    +        others = sum(v.get(x, 0) for x in otherkeys)
    
    91
    +        print(k + '\t' + '\t'.join([str(v.get(x, 0)) for x in keystolist] + showothers * [str(others)]), file=f)
    
    98 92
         f.flush()
    
    99
    -    n = f.name
    
    100 93
     
    
    101 94
         p = os.popen("R --vanilla --slave > /dev/null", "w")
    
    102 95
         p.write("""
    
    ... ... @@ -121,7 +114,7 @@ def dump_file(outfn, keystolist, showothers):
    121 114
     
    
    122 115
       dev.off()
    
    123 116
       q()
    
    124
    -  """ % {'datafile': n, 'outfile': outfn,
    
    117
    +  """ % {'datafile': f.name, 'outfile': outfn,
    
    125 118
            'title': ((not showothers) * "partial ") + "dinstall times"})
    
    126 119
         p.flush()
    
    127 120
         assert not p.close()
    


  • Reply to: