mirror of
https://github.com/JimmXinu/FanFicFare.git
synced 2026-05-09 05:21:13 +02:00
Make INI order tool py2/py3.
This commit is contained in:
parent
32857a9dad
commit
389eb8969c
1 changed files with 21 additions and 6 deletions
27
ini-order.py
27
ini-order.py
|
|
@ -1,16 +1,31 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2018, Jim Miller
|
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import re
|
||||
import sys
|
||||
from io import open # so py2.7 has open with encoding param.
|
||||
|
||||
argv = sys.argv[1:]
|
||||
|
||||
# infile = argv[0]
|
||||
# outfile = argv[1]
|
||||
|
||||
sections = {}
|
||||
cursectname = ""
|
||||
cursectlines = []
|
||||
|
||||
with open(argv[0],"r") as infile:
|
||||
with open(argv[0],"r", encoding="utf8") as infile:
|
||||
for line in infile:
|
||||
if re.match(r"^\[([^\]]+)\]$",line):
|
||||
sections[cursectname] = cursectlines
|
||||
|
|
@ -40,8 +55,8 @@ leadsects = [
|
|||
followsects = [
|
||||
]
|
||||
|
||||
with open(argv[1],"w") as outfile:
|
||||
kl = sections.keys()
|
||||
with open(argv[1],"w", encoding="utf8") as outfile:
|
||||
kl = list(sections.keys())
|
||||
kl.sort()
|
||||
for k in leadsects:
|
||||
outfile.write("".join(sections[k]))
|
||||
|
|
|
|||
Loading…
Reference in a new issue