Advertisement
sandlbn

MorphOS ISO to UTF

Jun 16th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. #!python
  2. from subprocess import call,PIPE
  3. from os import getcwd,walk,path,system
  4. from sys import argv
  5.  
  6. error_string = "use conv --from-django or --to-django to convert files"
  7. directory = getcwd()
  8. national_code = "ISO8859-2"
  9. file_extension = ".py"
  10. temp = "RAM:temp_file"
  11.  
  12. try:
  13.     opts = argv[1]
  14. except IndexError:
  15.     pass
  16.    
  17.    
  18. def parse(f,t):
  19.     cfiles = [path.join(root, filename)
  20.             for root, dirnames, filenames in walk(directory)
  21.             for filename in filenames if filename.endswith(file_extension)]
  22.     for orgfile in cfiles:
  23.         print "Processing {0} file ".format(orgfile)
  24.         system("iconv -f {0} -t {1} {2} > {3}".format(f,t,orgfile,temp))
  25.         system("copy {0} {1}".format(temp,orgfile))
  26.     system("delete {0}".format(temp))
  27.    
  28. try:
  29.     if opts == "--from-django":
  30.         f =  "utf-8"
  31.         t =  national_code
  32.         parse(f,t)
  33.     elif opts == "--to-django":
  34.         t =  "utf-8"
  35.         f =  national_code
  36.         parse(f,t)
  37.     else:
  38.         print error_string
  39. except NameError:
  40.     print  error_string
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement