Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!python
- from subprocess import call,PIPE
- from os import getcwd,walk,path,system
- from sys import argv
- error_string = "use conv --from-django or --to-django to convert files"
- directory = getcwd()
- national_code = "ISO8859-2"
- file_extension = ".py"
- temp = "RAM:temp_file"
- try:
- opts = argv[1]
- except IndexError:
- pass
- def parse(f,t):
- cfiles = [path.join(root, filename)
- for root, dirnames, filenames in walk(directory)
- for filename in filenames if filename.endswith(file_extension)]
- for orgfile in cfiles:
- print "Processing {0} file ".format(orgfile)
- system("iconv -f {0} -t {1} {2} > {3}".format(f,t,orgfile,temp))
- system("copy {0} {1}".format(temp,orgfile))
- system("delete {0}".format(temp))
- try:
- if opts == "--from-django":
- f = "utf-8"
- t = national_code
- parse(f,t)
- elif opts == "--to-django":
- t = "utf-8"
- f = national_code
- parse(f,t)
- else:
- print error_string
- except NameError:
- print error_string
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement