Attachment 'random_file.py'
Download 1 # Use: python random_file.py /path/to/sage/devel/sage-branch
2
3 import sys, os, re, random
4
5 all = []
6
7 for dir, dirnames, filenames in os.walk(sys.argv[1]):
8 for file in filenames:
9 if file[-4:] == ".pyx" or file[-3:] == ".py":
10 all.append("%s/%s" % (dir, file))
11
12 content = ""
13 while len(content) < 1000:
14 file = random.choice(all)
15 content = open(file).read()
16 content = re.sub(re.compile(r'""".*?"""', re.DOTALL), '"""..."""', content)
17 content = re.sub(re.compile(r'class *[^ ]*?', re.DOTALL), 'class ...', content)
18 content = re.sub(re.compile(r'def is_*[^ ]*?', re.DOTALL), 'is_...', content)
19
20 lines = content.split('\n')
21 start = random.randint(0, max(1, len(lines)-200))
22 lines = lines[start:]
23 contents = "\n".join(lines + ['\n'] * 1000)
24
25 open("tmp.txt", "w").write(contents)
26 os.system("more tmp.txt")
27
28 print "\n\n"
29 print file
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.