X7ROOT File Manager
Current Path:
/lib64/python2.7/Demo/scripts
lib64
/
python2.7
/
Demo
/
scripts
/
??
..
??
README
(1009 B)
??
beer.py
(458 B)
??
beer.pyc
(703 B)
??
beer.pyo
(703 B)
??
eqfix.py
(6.16 KB)
??
eqfix.pyc
(4.53 KB)
??
eqfix.pyo
(4.53 KB)
??
fact.py
(1.11 KB)
??
fact.pyc
(1.14 KB)
??
fact.pyo
(1.14 KB)
??
find-uname.py
(1.18 KB)
??
find-uname.pyc
(1.47 KB)
??
find-uname.pyo
(1.47 KB)
??
from.py
(873 B)
??
from.pyc
(751 B)
??
from.pyo
(751 B)
??
lpwatch.py
(2.77 KB)
??
lpwatch.pyc
(2.54 KB)
??
lpwatch.pyo
(2.54 KB)
??
makedir.py
(509 B)
??
makedir.pyc
(732 B)
??
makedir.pyo
(732 B)
??
markov.py
(3.5 KB)
??
markov.pyc
(3.93 KB)
??
markov.pyo
(3.93 KB)
??
mboxconvert.py
(3.11 KB)
??
mboxconvert.pyc
(3.18 KB)
??
mboxconvert.pyo
(3.18 KB)
??
morse.py
(4.21 KB)
??
morse.pyc
(4.33 KB)
??
morse.pyo
(4.33 KB)
??
pi.py
(887 B)
??
pi.pyc
(921 B)
??
pi.pyo
(921 B)
??
pp.py
(3.72 KB)
??
pp.pyc
(2.28 KB)
??
pp.pyo
(2.28 KB)
??
primes.py
(602 B)
??
primes.pyc
(921 B)
??
primes.pyo
(921 B)
??
queens.py
(2.19 KB)
??
queens.pyc
(2.95 KB)
??
queens.pyo
(2.95 KB)
??
script.py
(961 B)
??
script.pyc
(1.21 KB)
??
script.pyo
(1.21 KB)
??
unbirthday.py
(3.07 KB)
??
unbirthday.pyc
(2.93 KB)
??
unbirthday.pyo
(2.93 KB)
??
update.py
(2.68 KB)
??
update.pyc
(2.69 KB)
??
update.pyo
(2.69 KB)
Editing: update.py
#! /usr/bin/python2.7 # Update a bunch of files according to a script. # The input file contains lines of the form <filename>:<lineno>:<text>, # meaning that the given line of the given file is to be replaced # by the given text. This is useful for performing global substitutions # on grep output: import os import sys import re pat = '^([^: \t\n]+):([1-9][0-9]*):' prog = re.compile(pat) class FileObj: def __init__(self, filename): self.filename = filename self.changed = 0 try: self.lines = open(filename, 'r').readlines() except IOError, msg: print '*** Can\'t open "%s":' % filename, msg self.lines = None return print 'diffing', self.filename def finish(self): if not self.changed: print 'no changes to', self.filename return try: os.rename(self.filename, self.filename + '~') fp = open(self.filename, 'w') except (os.error, IOError), msg: print '*** Can\'t rewrite "%s":' % self.filename, msg return print 'writing', self.filename for line in self.lines: fp.write(line) fp.close() self.changed = 0 def process(self, lineno, rest): if self.lines is None: print '(not processed): %s:%s:%s' % ( self.filename, lineno, rest), return i = eval(lineno) - 1 if not 0 <= i < len(self.lines): print '*** Line number out of range: %s:%s:%s' % ( self.filename, lineno, rest), return if self.lines[i] == rest: print '(no change): %s:%s:%s' % ( self.filename, lineno, rest), return if not self.changed: self.changed = 1 print '%sc%s' % (lineno, lineno) print '<', self.lines[i], print '---' self.lines[i] = rest print '>', self.lines[i], def main(): if sys.argv[1:]: try: fp = open(sys.argv[1], 'r') except IOError, msg: print 'Can\'t open "%s":' % sys.argv[1], msg sys.exit(1) else: fp = sys.stdin curfile = None while 1: line = fp.readline() if not line: if curfile: curfile.finish() break n = prog.match(line) if n < 0: print 'Funny line:', line, continue filename, lineno = prog.group(1, 2) if not curfile or filename <> curfile.filename: if curfile: curfile.finish() curfile = FileObj(filename) curfile.process(lineno, line[n:]) if __name__ == "__main__": main()
Upload File
Create Folder