diff --git a/auto_sort/README.md b/auto_sort/README.md index d5d8dca..6861344 100644 --- a/auto_sort/README.md +++ b/auto_sort/README.md @@ -1,8 +1,9 @@ - [English](#introduction) - [中文](#介绍) +- [Português (Brasil)](#Português (Brasil)) # Introduction -`asort.py` is a very simple python3 script that aims to make sure items in the README file of the repo [Awesome-Linux-Software](https://github.com/VoLuong/Awesome-Linux-Software) are sorted alphabetically. +`asort.py` is a very simple python3 script that aims to make sure items in the README file of the repo [Awesome-Linux-Software](https://github.com/VoLuong/Awesome-Linux-Software) are sorted alphabetically. This script only sorts items in the following topics for now (items between topic Applications and topic Setup): - Applications @@ -48,3 +49,26 @@ MIT License. # 许可 MIT 许可协议。 +--------------------------------------------- +# Português (Brasil) +`asort.py` é um script python3 muito simples, que visa garantir que os itens no arquivo README do repositório [Awesome-Linux-Software](https://github.com/VoLuong/Awesome-Linux-Software) sejam ordenados alfabeticamente. + +Este script apenas classifica itens nos seguintes tópicos por enquanto (Itens entre os tópicos Aplicativos e Configuração): +- Aplicativos +- Utilitários de linha de comando +- Ambiente de trabalho +- Gestores de exibição +- Gestor de janelas + +# Modo de usar +1. Adicione itens aos tópicos correspondentes, não se preocupe com a ordem desses itens. +1. Verifique se está instalado o ambiente python3 em seu sistema. +1. Abra o terminal e digite `python3 asort.py` para executar o script. Depois disso, você receberá um novo arquivo README com todos os itens nos tópicos acima classificados em ordem alfabética. + +![test screenshot](./test.png) + +## Nota +`asort_pt-BR.py` funciona no arquivo [README_pt-BR.md](https://github.com/VoLuong/Awesome-Linux-Software/blob/master/README_pt-BR.md), versão Portugês Brasileira desta lista. + +# Licença +Licença MIT. diff --git a/auto_sort/asort_pt-BR.py b/auto_sort/asort_pt-BR.py new file mode 100644 index 0000000..16dce1e --- /dev/null +++ b/auto_sort/asort_pt-BR.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 +# -*-coding: utf-8-*- +# Author : Christopher L +# Blog : http://blog.chriscabin.com +# GitHub : https://www.github.com/chrisleegit +# File : asort.py +# Date : 2016/08/22 11:12 +# Version: 0.1 +# Description: A very simple python script that can sort items alphabetically. + +from __future__ import print_function +import os +import shutil + + +README_FILE = '../README_pt-BR.md' +TEMP_FILE = 'temp_pt-BR.md' + +# only works for those items between BEGIN and END. +BEGIN = '## Aplicativos' +END = '## Configuração' + + +def main(): + global README_FILE + + # make sure the script can find file: README.md + README_FILE = os.path.abspath(README_FILE) + + if not os.path.exists(README_FILE): + print('Erro: Arquivo ou diretório não existe: {}'.format(README_FILE)) + exit(1) + + sort_enable = False + items = list() + + print('Carregando arquivo: {}'.format(README_FILE)) + + # read file: README.md + with open(README_FILE) as infile, open(TEMP_FILE, 'w') as outfile: + # process each line + for line in infile: + if not sort_enable and BEGIN in line: + sort_enable = True + + # if sort_enable and END in line: + # sort_enable = False + + if sort_enable: + line = line.strip() + + # each item starts with a character '-' (maybe '*' and '+') + if line.startswith(('-', '*', '+')): + items.append(line) + elif line.startswith('#'): + sort_enable = False if END in line else True + + # 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()): + # write the ordered list to the temporary file. + print(item, file=outfile) + print('', file=outfile) + items.clear() + + # remember to put the next header in the temporary file. + print(line, file=outfile) + else: + print(line, end='', file=outfile) + else: + print(line, end='', file=outfile) + + print('Substitua o arquivo original: README_pt-BR.md') + shutil.move(TEMP_FILE, README_FILE) + + +if __name__ == '__main__': + main()