File: .scrub_docstrings.py

package info (click to toggle)
shogun 0.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 8,688 kB
  • ctags: 6,563
  • sloc: cpp: 61,677; python: 5,233; sh: 2,767; makefile: 555; objc: 37
file content (48 lines) | stat: -rw-r--r-- 959 bytes parent folder | download
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
#!/usr/bin/env python

import sys
import os

# has to be ordered tuple
REPLACEMENTS=[
	[' DREAL', ' float'],
	[' SHORTREAL', ' float'],
	[' LONGREAL', ' float'],
	[' double', ' float'],
	[' INT', '  int'],
	[' UINT', ' int'],
	[' LONG', ' int'],
	[' ULONG', ' int'],
	[' BYTE', ' int'],
	[' SHORT', ' int'],
	[' WORD', ' int'],
	[' CHAR', ' str'],
	['-> CFeatures', '-> Features'],
]

class Scrub:
	def __init__ (self, extension, input):
		self.infile=input+extension
		self.outfile=self.infile+'.new'

	def run (self):
		input=open(self.infile, 'r')
		output=open(self.outfile, 'w')

		for text in input.xreadlines():
			for pairs in REPLACEMENTS:
				text=text.replace(pairs[0], pairs[1])
			output.write(text)

		input.close()
		output.close()

		os.rename(self.outfile, self.infile)


if __name__=='__main__':
	offset=sys.argv[2].find('_wrap.cxx')
	if sys.argv[1] == 'stop':
		sys.exit(0)
	scrubby=Scrub(sys.argv[1], sys.argv[2][0:offset])
	scrubby.run()