nivs

PyQT.docx -> *.py

Jan 19th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. __author__ = 'nivs'
  2. import re
  3. import os
  4. import shutil
  5. import copy
  6. book = open('text.txt','r')
  7. file = ""
  8. nameOfList = {}
  9. lvl = 0
  10. root = "/home/nivs/projects/python/my_programs/PyQTBook/"
  11. buf1 = ""
  12. buf2 = ""
  13. start = True
  14. for line in book.readlines():
  15.     if not re.match(r"\n", line):
  16.         reg = re.match(r"^((?!Листинг)[а-яА-ЯM].*)", line)
  17.         reg2 = re.match(r"Листинг \d+\. (.*)", line)
  18.         if reg:
  19.             lvl += 1
  20.             if lvl == 2:
  21.                 buf2 = reg.group(1)
  22.             elif lvl == 1:
  23.                 buf1 = reg.group(1)
  24.                 if not start:
  25.                     file.close()
  26.         elif reg2:
  27.             start = False
  28.             if lvl == 2:
  29.                 os.makedirs(root + buf2)
  30.                 os.makedirs(root + buf2 + "/" + buf1)
  31.                 lvl = 0
  32.                 file = open(root + buf2 + "/" + buf1 + "/" + reg2.group(1), "w")
  33.                 file.writelines("#!/usr/bin/python3\n")
  34.             elif lvl == 1:
  35.                 os.makedirs(root + buf2 + "/" + buf1)
  36.                 lvl = 0
  37.                 file = open(root + buf2 + "/" + buf1 + "/" + reg2.group(1), "w")
  38.                 file.writelines("#!/usr/bin/python3\n")
  39.             else:
  40.                 lvl = 0
  41.                 file = open(root + buf2 + "/" + buf1 + "/" + reg2.group(1), "w")
  42.                 file.writelines("#!/usr/bin/python3\n")
  43.         else:
  44.             file.writelines(line)
  45. print("_" * 30)
Advertisement
Add Comment
Please, Sign In to add comment