File: concatlines.py

package info (click to toggle)
dwarfutils 20201201-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 11,868 kB
  • sloc: ansic: 104,667; sh: 5,947; cpp: 4,675; python: 878; makefile: 646; awk: 11
file content (110 lines) | stat: -rw-r--r-- 2,031 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/python3
# extracts a couple preferred numbers from the /bin/time output
# interspersed with script output...
# From running a debug dwarfdump.
# David Anderson March 2013.


import sys

def extractnum(w):
  r = ""
  dot="n"
  for c in w:
    if c.isdigit():
       r = r + c
       continue
    if c == '.':
       dot = "y"
       r = r + c
       continue
    return r,dot
  return r,dot
    

def istime(w):
  """ Return "y" if the number looks like a time: d*.d*  """
  t,d = extractnum(w)
  if len(t) < 4:
    return "n"
  if  d == "n":
    return "n"
  if w[0].isdigit():
    if w[1].isdigit:
      return "y"
    elif w[1] == '.':
      return "y"
  return "n"

def findfinal(d):
  beforenums = "y"
  wds = d.split()
  o= ""
  o2 = ""
  for w in wds: 
    if istime(w) == "y":
      beforenums = "n"
    if beforenums == "y":
      o += " "
      o += w
      continue
    else:
      if w.endswith("user"):
          t = ""
          for c in w:
             if not c == "u": 
               t += c
             else:
               o2 += " "
               o2 += t
      elif w.endswith("maxresident)k"):
          t = ""
          for c in w:
             if not c == "m": 
               t += c
             else:
               o2 += " "
               o2 += t
      else:
          ign = ""
  return (o,o2)

final = ""
myfile = sys.stdin
ct = 0
#if len(sys.argv) > 1:
#  print("argv[1] = ", sys.argv[1])
#  v = sys.argv[1]
#  if v == "-t":
#    testonly = "y"
#  elif v == "-v":
#    testonly = "v"
#  else:
#    print("Argument: ", v, " unknown, exiting.")
#    sys.exit(1)

while 1:
  #if int(ct) > 5:
  #    break;
  ct = ct + 1
  try:
    rec = myfile.readline()
  except:
    print(final)
    break

  if len(rec)  < 1:
    f,v = findfinal(final)
    print(v,f)
    break;
  if rec.startswith("===") == 1:
    f,v = findfinal(final)
    print(v,f)
    final = rec.strip()
  else:
    if rec.startswith("Command") == 1:
      disc = rec.strip() 
    else:
      final += " "
      final += rec.strip()