mirror of
https://github.com/luong-komorebi/Awesome-Linux-Software.git
synced 2025-09-02 18:33:15 +02:00
Sourcery refactored master branch (#747)
Co-authored-by: Sourcery AI <>
This commit is contained in:
@@ -30,16 +30,16 @@ def main():
|
|||||||
README_FILE = os.path.abspath(README_FILE)
|
README_FILE = os.path.abspath(README_FILE)
|
||||||
|
|
||||||
if not os.path.exists(README_FILE):
|
if not os.path.exists(README_FILE):
|
||||||
print('Error: no such file or directory: {}'.format(README_FILE))
|
print(f'Error: no such file or directory: {README_FILE}')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
sort_enable = False
|
sort_enable = False
|
||||||
items = list()
|
items = []
|
||||||
|
|
||||||
print('Loading file: {}'.format(README_FILE))
|
print(f'Loading file: {README_FILE}')
|
||||||
|
|
||||||
# read file: README.md
|
# read file: README.md
|
||||||
with open(README_FILE) as infile, open(TEMP_FILE, 'w') as outfile:
|
with (open(README_FILE) as infile, open(TEMP_FILE, 'w') as outfile):
|
||||||
# process each line
|
# process each line
|
||||||
for line in infile:
|
for line in infile:
|
||||||
if not sort_enable and BEGIN in line:
|
if not sort_enable and BEGIN in line:
|
||||||
@@ -48,29 +48,28 @@ def main():
|
|||||||
# if sort_enable and END in line:
|
# if sort_enable and END in line:
|
||||||
# sort_enable = False
|
# sort_enable = False
|
||||||
|
|
||||||
if sort_enable:
|
if sort_enable and line.startswith(('-')):
|
||||||
# each item starts with a character '-'
|
line = line.strip()
|
||||||
if line.startswith(('-')):
|
items.append(line)
|
||||||
line = line.strip()
|
elif sort_enable and not line.startswith(('-')) and line == '\n':
|
||||||
items.append(line)
|
# when we meet the next header, we should stop adding new item to the list.
|
||||||
# When no more items, blank line or new header
|
for item in sorted(items, key=lambda x: regex.findall(x.upper())[len(regex.findall(x.upper()))-1]):
|
||||||
elif line == '\n':
|
# write the ordered list to the temporary file.
|
||||||
# when we meet the next header, we should stop adding new item to the list.
|
print(item, file=outfile)
|
||||||
for item in sorted(items, key=lambda x: regex.findall(x.upper())[len(regex.findall(x.upper()))-1]):
|
items.clear()
|
||||||
# write the ordered list to the temporary file.
|
|
||||||
print(item, file=outfile)
|
|
||||||
items.clear()
|
|
||||||
|
|
||||||
# remember to put the next header in the temporary file.
|
# remember to put the next header in the temporary file.
|
||||||
print(line, end='', file=outfile)
|
print(line, end='', file=outfile)
|
||||||
elif line.startswith('#'):
|
elif (
|
||||||
sort_enable = False if END in line else True
|
sort_enable
|
||||||
print(line, end='', file=outfile)
|
and not line.startswith(('-'))
|
||||||
else:
|
and line != '\n'
|
||||||
print(line, end='', file=outfile)
|
and line.startswith('#')
|
||||||
|
):
|
||||||
|
sort_enable = END not in line
|
||||||
|
print(line, end='', file=outfile)
|
||||||
else:
|
else:
|
||||||
print(line, end='', file=outfile)
|
print(line, end='', file=outfile)
|
||||||
|
|
||||||
print('Replace the original file: README.md')
|
print('Replace the original file: README.md')
|
||||||
shutil.move(TEMP_FILE, README_FILE)
|
shutil.move(TEMP_FILE, README_FILE)
|
||||||
|
|
||||||
|
@@ -28,44 +28,43 @@ def main():
|
|||||||
README_FILE = os.path.abspath(README_FILE)
|
README_FILE = os.path.abspath(README_FILE)
|
||||||
|
|
||||||
if not os.path.exists(README_FILE):
|
if not os.path.exists(README_FILE):
|
||||||
print('Error: archivo o directorio no existe: {}'.format(README_FILE))
|
print(f'Error: archivo o directorio no existe: {README_FILE}')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
sort_enable = False
|
sort_enable = False
|
||||||
items = []
|
items = []
|
||||||
|
|
||||||
print('Cargando archivo: {}'.format(README_FILE))
|
print(f'Cargando archivo: {README_FILE}')
|
||||||
|
|
||||||
# Read the file: README.md
|
# Read the file: README.md
|
||||||
with open(README_FILE, 'r') as infile, open(TEMP_FILE, 'w') as outfile:
|
with (open(README_FILE, 'r') as infile, open(TEMP_FILE, 'w') as outfile):
|
||||||
# Process each line
|
# Process each line
|
||||||
for line in infile:
|
for line in infile:
|
||||||
if not sort_enable and BEGIN in line:
|
if not sort_enable and BEGIN in line:
|
||||||
sort_enable = True
|
sort_enable = True
|
||||||
|
|
||||||
if sort_enable:
|
if sort_enable and line.startswith('-'):
|
||||||
# Each item starts with a character '-'
|
line = line.strip()
|
||||||
if line.startswith('-'):
|
items.append(line)
|
||||||
line = line.strip()
|
elif sort_enable and not line.startswith('-') and line == '\n':
|
||||||
items.append(line)
|
# When we meet the next header, we should stop adding new items to the list.
|
||||||
# When no more items, blank line or new header
|
for item in sorted(items, key=lambda x: regex.findall(x.upper())[-1]):
|
||||||
elif line == '\n':
|
# Write the ordered list to the temporary file.
|
||||||
# When we meet the next header, we should stop adding new items to the list.
|
print(item, file=outfile)
|
||||||
for item in sorted(items, key=lambda x: regex.findall(x.upper())[-1]):
|
items.clear()
|
||||||
# Write the ordered list to the temporary file.
|
|
||||||
print(item, file=outfile)
|
|
||||||
items.clear()
|
|
||||||
|
|
||||||
# Remember to put the next header in the temporary file.
|
# Remember to put the next header in the temporary file.
|
||||||
print(line, end='', file=outfile)
|
print(line, end='', file=outfile)
|
||||||
elif line.startswith('#'):
|
elif (
|
||||||
sort_enable = False if END in line else True
|
sort_enable
|
||||||
print(line, end='', file=outfile)
|
and not line.startswith('-')
|
||||||
else:
|
and line != '\n'
|
||||||
print(line, end='', file=outfile)
|
and line.startswith('#')
|
||||||
|
):
|
||||||
|
sort_enable = END not in line
|
||||||
|
print(line, end='', file=outfile)
|
||||||
else:
|
else:
|
||||||
print(line, end='', file=outfile)
|
print(line, end='', file=outfile)
|
||||||
|
|
||||||
print('Reemplazar el archivo original: README_es-ES.md')
|
print('Reemplazar el archivo original: README_es-ES.md')
|
||||||
shutil.move(TEMP_FILE, README_FILE)
|
shutil.move(TEMP_FILE, README_FILE)
|
||||||
|
|
||||||
|
@@ -28,16 +28,16 @@ def main():
|
|||||||
README_FILE = os.path.abspath(README_FILE)
|
README_FILE = os.path.abspath(README_FILE)
|
||||||
|
|
||||||
if not os.path.exists(README_FILE):
|
if not os.path.exists(README_FILE):
|
||||||
print('Erro: Arquivo ou diretório não existe: {}'.format(README_FILE))
|
print(f'Erro: Arquivo ou diretório não existe: {README_FILE}')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
sort_enable = False
|
sort_enable = False
|
||||||
items = list()
|
items = []
|
||||||
|
|
||||||
print('Carregando arquivo: {}'.format(README_FILE))
|
print(f'Carregando arquivo: {README_FILE}')
|
||||||
|
|
||||||
# read file: README.md
|
# read file: README.md
|
||||||
with open(README_FILE) as infile, open(TEMP_FILE, 'w') as outfile:
|
with (open(README_FILE) as infile, open(TEMP_FILE, 'w') as outfile):
|
||||||
# process each line
|
# process each line
|
||||||
for line in infile:
|
for line in infile:
|
||||||
if not sort_enable and BEGIN in line:
|
if not sort_enable and BEGIN in line:
|
||||||
@@ -53,7 +53,7 @@ def main():
|
|||||||
if line.startswith(('-', '*', '+')):
|
if line.startswith(('-', '*', '+')):
|
||||||
items.append(line)
|
items.append(line)
|
||||||
elif line.startswith('#'):
|
elif line.startswith('#'):
|
||||||
sort_enable = False if END in line else True
|
sort_enable = END not in line
|
||||||
|
|
||||||
# when we meet the next header, we should stop adding new item to the list.
|
# when we meet the next header, we should stop adding new item to the list.
|
||||||
for item in sorted(items, key=lambda x: x.upper()):
|
for item in sorted(items, key=lambda x: x.upper()):
|
||||||
|
@@ -30,16 +30,16 @@ def main():
|
|||||||
README_FILE = os.path.abspath(README_FILE)
|
README_FILE = os.path.abspath(README_FILE)
|
||||||
|
|
||||||
if not os.path.exists(README_FILE):
|
if not os.path.exists(README_FILE):
|
||||||
print('Error: no such file or directory: {}'.format(README_FILE))
|
print(f'Error: no such file or directory: {README_FILE}')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
sort_enable = False
|
sort_enable = False
|
||||||
items = list()
|
items = []
|
||||||
|
|
||||||
print('Loading file: {}'.format(README_FILE))
|
print(f'Loading file: {README_FILE}')
|
||||||
|
|
||||||
# read file: README.md
|
# read file: README.md
|
||||||
with open(README_FILE) as infile, open(TEMP_FILE, 'w') as outfile:
|
with (open(README_FILE) as infile, open(TEMP_FILE, 'w') as outfile):
|
||||||
# process each line
|
# process each line
|
||||||
for line in infile:
|
for line in infile:
|
||||||
if not sort_enable and BEGIN in line:
|
if not sort_enable and BEGIN in line:
|
||||||
@@ -48,29 +48,28 @@ def main():
|
|||||||
# if sort_enable and END in line:
|
# if sort_enable and END in line:
|
||||||
# sort_enable = False
|
# sort_enable = False
|
||||||
|
|
||||||
if sort_enable:
|
if sort_enable and line.startswith(('-')):
|
||||||
# each item starts with a character '-'
|
line = line.strip()
|
||||||
if line.startswith(('-')):
|
items.append(line)
|
||||||
line = line.strip()
|
elif sort_enable and not line.startswith(('-')) and line == '\n':
|
||||||
items.append(line)
|
# when we meet the next header, we should stop adding new item to the list.
|
||||||
# When no more items, blank line or new header
|
for item in sorted(items, key=lambda x: regex.findall(x.upper())[len(regex.findall(x.upper()))-1]):
|
||||||
elif line == '\n':
|
# write the ordered list to the temporary file.
|
||||||
# when we meet the next header, we should stop adding new item to the list.
|
print(item, file=outfile)
|
||||||
for item in sorted(items, key=lambda x: regex.findall(x.upper())[len(regex.findall(x.upper()))-1]):
|
items.clear()
|
||||||
# write the ordered list to the temporary file.
|
|
||||||
print(item, file=outfile)
|
|
||||||
items.clear()
|
|
||||||
|
|
||||||
# remember to put the next header in the temporary file.
|
# remember to put the next header in the temporary file.
|
||||||
print(line, end='', file=outfile)
|
print(line, end='', file=outfile)
|
||||||
elif line.startswith('#'):
|
elif (
|
||||||
sort_enable = False if END in line else True
|
sort_enable
|
||||||
print(line, end='', file=outfile)
|
and not line.startswith(('-'))
|
||||||
else:
|
and line != '\n'
|
||||||
print(line, end='', file=outfile)
|
and line.startswith('#')
|
||||||
|
):
|
||||||
|
sort_enable = END not in line
|
||||||
|
print(line, end='', file=outfile)
|
||||||
else:
|
else:
|
||||||
print(line, end='', file=outfile)
|
print(line, end='', file=outfile)
|
||||||
|
|
||||||
print('Replace the original file: README_zh-CN.md')
|
print('Replace the original file: README_zh-CN.md')
|
||||||
shutil.move(TEMP_FILE, README_FILE)
|
shutil.move(TEMP_FILE, README_FILE)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user