File: clean.py

package info (click to toggle)
zim 0.62-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 7,660 kB
  • ctags: 6,996
  • sloc: python: 52,094; xml: 1,135; makefile: 45; sh: 36
file content (34 lines) | stat: -rwxr-xr-x 754 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/python

'''Tool to cleanup the source directory'''

import os
import sys
import shutil
from subprocess import Popen, PIPE

def main(remove=False):
	pipe = Popen('bzr ls --ignored', shell=True, stdout=PIPE).stdout
	print 'rm *.pyc'
	for line in pipe.readlines():
		file = line.strip()
		if os.path.isfile(file):
			if not file.endswith('.pyc'):
				print 'rm %s' % file
			if remove:
				os.remove(file)
		elif os.path.isdir(file):
			print 'rmtree %s' % file
			if remove:
				shutil.rmtree(file)
	pipe.close()

if __name__ == '__main__':
	warning = '\n### This is a test run, use --force to really delete\n'

	if len(sys.argv) == 2 and sys.argv[1] == '--force':
		main(remove=True)
	else:
		print warning
		main(remove=False)
		print warning