2017-12-29 12:43:05 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Gets all the files in SOURCES_TREE directory, shows all level headers for each file and skip or process files by user's selection.
|
|
|
|
|
2018-02-21 16:09:32 +00:00
|
|
|
import os
|
2017-12-29 12:43:05 +00:00
|
|
|
|
|
|
|
SOURCES_TREE = 'ru'
|
|
|
|
STOP_AT_THE_FIRST_FILE = False
|
|
|
|
|
2018-02-21 16:09:32 +00:00
|
|
|
for (dirpath, dirnames, filenames) in os.walk(SOURCES_TREE):
|
|
|
|
for filename in filenames:
|
|
|
|
if filename == 'conf.py':
|
|
|
|
continue
|
2017-12-29 12:43:05 +00:00
|
|
|
|
2018-02-21 16:09:32 +00:00
|
|
|
print '=== ' + dirpath + '/' + filename
|
2017-12-29 12:43:05 +00:00
|
|
|
|
2018-02-21 16:09:32 +00:00
|
|
|
f = open(dirpath + '/' + filename)
|
2017-12-29 12:43:05 +00:00
|
|
|
content = f.readlines()
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
|
|
# Showing headers structure in md-file
|
|
|
|
count_lines = 0
|
|
|
|
for l in content:
|
2018-02-21 16:09:32 +00:00
|
|
|
if l.startswith('#'):
|
|
|
|
print l
|
|
|
|
if l.startswith('==='):
|
|
|
|
print content[count_lines - 1] + l
|
|
|
|
if l.startswith('---'):
|
|
|
|
print content[count_lines - 1] + l
|
2017-12-29 12:43:05 +00:00
|
|
|
count_lines += 1
|
|
|
|
|
|
|
|
# At this stage user should check the headers structucture and choose what to to
|
|
|
|
# Replace headers markup or not
|
2018-02-21 16:09:32 +00:00
|
|
|
choise = raw_input('What to do with a file (pass(s) or process(p)): ')
|
2017-12-29 12:43:05 +00:00
|
|
|
|
2018-02-21 16:09:32 +00:00
|
|
|
if choise == 's':
|
|
|
|
continue
|
2017-12-29 12:43:05 +00:00
|
|
|
else:
|
2018-02-21 16:09:32 +00:00
|
|
|
print 'processing...'
|
2017-12-29 12:43:05 +00:00
|
|
|
count_lines = 0
|
|
|
|
for l in content:
|
2018-02-21 16:09:32 +00:00
|
|
|
if l.startswith('==='):
|
2017-12-29 12:43:05 +00:00
|
|
|
print count_lines, content[count_lines -1], content[count_lines]
|
2018-02-21 16:09:32 +00:00
|
|
|
content[count_lines - 1] = '# ' + content[count_lines - 1]
|
2017-12-29 12:43:05 +00:00
|
|
|
content.pop(count_lines)
|
|
|
|
|
2018-02-21 16:09:32 +00:00
|
|
|
if l.startswith('---'):
|
2017-12-29 12:43:05 +00:00
|
|
|
print count_lines, content[count_lines -1], content[count_lines]
|
2018-02-21 16:09:32 +00:00
|
|
|
content[count_lines - 1] = '## ' + content[count_lines - 1]
|
2017-12-29 12:43:05 +00:00
|
|
|
content.pop(count_lines)
|
|
|
|
|
|
|
|
count_lines += 1
|
|
|
|
|
2018-02-21 16:09:32 +00:00
|
|
|
f = open(dirpath + '/' + filename, 'w')
|
|
|
|
for l in content:
|
|
|
|
f.write(l)
|
2017-12-29 12:43:05 +00:00
|
|
|
f.close()
|
|
|
|
|
2018-02-21 16:09:32 +00:00
|
|
|
if STOP_AT_THE_FIRST_FILE:
|
|
|
|
break
|
2017-12-29 12:43:05 +00:00
|
|
|
|
2018-02-21 16:09:32 +00:00
|
|
|
if STOP_AT_THE_FIRST_FILE:
|
|
|
|
break
|