-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from lucasferreiralimax/i18n
i18n and refactory folders
- Loading branch information
Showing
24 changed files
with
300 additions
and
123 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from .projects_update import projects_update | ||
from .ncu_update import ncu_update | ||
from .get_cli_version import get_cli_version | ||
from .check_outdated import check_outdated | ||
from .check_status import check_status | ||
|
||
# Exportando funções/módulos | ||
__all__ = ["projects_update", "ncu_update", "get_cli_version", "check_outdated", "check_status"] |
9 changes: 5 additions & 4 deletions
9
src/commands/check_outdated.py → gitman/commands/check_outdated.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
import os | ||
import subprocess | ||
import i18n | ||
|
||
# Função para verificar dependências desatualizadas em todos os projetos | ||
def check_outdated(base_dir): | ||
for dir in os.listdir(base_dir): | ||
full_path = os.path.join(base_dir, dir) | ||
if os.path.isdir(full_path): | ||
print("Entrando no diretório:", full_path) | ||
print(i18n.t('check_outdated.entering_directory', fullpath=full_path)) | ||
os.chdir(full_path) | ||
|
||
try: | ||
print("Rodando 'outdated' em", full_path) | ||
print(i18n.t('check_outdated.running_outdated', fullpath=full_path)) | ||
subprocess.run(['npm', 'outdated'], check=True) | ||
|
||
except subprocess.CalledProcessError as e: | ||
print(f"Erro ao verificar dependências desatualizadas em {full_path}:") | ||
print(i18n.t('check_outdated.error', fullpath=full_path)) | ||
print(e.stderr) | ||
|
||
os.chdir('..') | ||
|
||
print("Verificação concluída.") | ||
print(i18n.t('check_status.complete_status')) |
11 changes: 6 additions & 5 deletions
11
src/commands/check_status.py → gitman/commands/check_status.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
import os | ||
import subprocess | ||
import i18n | ||
|
||
# Função para verificar o status do Git em todos os projetos | ||
def check_status(base_dir): | ||
for dir in os.listdir(base_dir): | ||
full_path = os.path.join(base_dir, dir) | ||
if os.path.isdir(full_path): | ||
print("Entrando no diretório:", full_path) | ||
print(i18n.t('check_status.entering_directory', fullpath=full_path)) | ||
os.chdir(full_path) | ||
|
||
try: | ||
print("Verificando o status do Git em", full_path) | ||
print(i18n.t('check_status.checking_git_status', fullpath=full_path)) | ||
subprocess.run(['git', 'status'], check=True) | ||
|
||
except subprocess.CalledProcessError as e: | ||
print(f"Erro ao verificar o status do Git em {full_path}:") | ||
print(i18n.t('check_status.git_error', fullpath=full_path)) | ||
print(e.stderr) | ||
|
||
os.chdir('..') | ||
print("Verificação de status do Git concluída.") | ||
|
||
print(i18n.t('check_status.complete_status')) |
5 changes: 3 additions & 2 deletions
5
src/commands/get_cli_version.py → gitman/commands/get_cli_version.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from importlib.metadata import version | ||
import i18n | ||
|
||
# Função para exibir a versão do programa | ||
def get_cli_version(): | ||
try: | ||
return version('gitman') | ||
print(i18n.t('comman.version', version=version('gitman'))) | ||
except Exception: | ||
return "Versão desconhecida" | ||
print(i18n.t('comman.version_not_found')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import i18n | ||
import platform | ||
import subprocess | ||
|
||
def i18nConfig(): | ||
# Obter informações do sistema | ||
system_info = platform.system() | ||
|
||
if system_info == 'Windows': | ||
# Para Windows, usando o módulo winreg para obter o idioma | ||
import winreg | ||
|
||
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Control Panel\\International", 0, winreg.KEY_READ) | ||
system_lang, _ = winreg.QueryValueEx(key, "LocaleName") | ||
winreg.CloseKey(key) | ||
|
||
elif system_info == 'Darwin': | ||
# Para macOS, usando o comando 'defaults' para obter o idioma | ||
proc = subprocess.Popen(['defaults', 'read', '-g', 'AppleLocale'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
out, _ = proc.communicate() | ||
system_lang = out.strip().decode('utf-8') | ||
|
||
else: | ||
# Para Linux e outros sistemas baseados em Unix, usando 'locale' para obter o idioma | ||
proc = subprocess.Popen(['locale'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
out, _ = proc.communicate() | ||
system_lang = out.split()[0].decode('utf-8').split('=')[1] | ||
|
||
if system_lang: | ||
system_lang = system_lang[:2] | ||
|
||
i18n.load_path.append('gitman/translations') | ||
i18n.set('fallback', 'en') | ||
i18n.set('locale', system_lang) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/env python3 | ||
import os | ||
import sys | ||
import i18n | ||
from .config import i18nConfig | ||
from .commands import projects_update | ||
from .commands import ncu_update | ||
from .commands import get_cli_version | ||
from .commands import check_outdated | ||
from .commands import check_status | ||
|
||
gitman = """ | ||
_______ __ .___________..___ ___. ___ .__ __. | ||
/ _____|| | | || \/ | / \ | \ | | | ||
| | __ | | `---| |----`| \ / | / ^ \ | \| | | ||
| | |_ | | | | | | |\/| | / /_\ \ | . ` | | ||
| |__| | | | | | | | | | / _____ \ | |\ | | ||
\______| |__| |__| |__| |__| /__/ \__\ |__| \__| | ||
""" | ||
|
||
# Função para exibir o uso correto do script | ||
def usage(): | ||
print(gitman) | ||
print(i18n.t('main.usage.description')) | ||
for i in range(1, 9): | ||
new_line = 'line' + str(i) | ||
print(i18n.t('main.usage.'+ new_line)) | ||
sys.exit(1) | ||
|
||
# Função principal do programa | ||
def app(): | ||
try: | ||
i18nConfig() | ||
|
||
# Verifica os parâmetros do script | ||
if len(sys.argv) == 1: | ||
usage() | ||
|
||
project_directory = "" | ||
ignored_dependencies = "" | ||
ncu_flag = False | ||
commit_message = "update: deps of project" | ||
base_directory = os.path.expanduser("~/Documents") | ||
|
||
# Processa os argumentos de linha de comando | ||
args = sys.argv[1:] | ||
while args: | ||
opt = args.pop(0) | ||
if opt == '-b': | ||
base_directory = os.path.expanduser(args.pop(0)) | ||
elif opt == '-u': | ||
project_directory = args.pop(0) | ||
elif opt == '-i': | ||
ignored_dependencies = args.pop(0) | ||
elif opt == '-a': | ||
check_outdated(base_directory) | ||
elif opt == '-g': | ||
check_status(base_directory) | ||
elif opt == '-n': | ||
project_directory = args.pop(0) | ||
ncu_flag = True | ||
elif opt == '-m': | ||
commit_message = args.pop(0) | ||
elif opt in ('-v', '--version'): | ||
get_cli_version() | ||
sys.exit(0) | ||
else: | ||
usage() | ||
|
||
# Executa o comando apropriado baseado nos parâmetros fornecidos | ||
if ncu_flag: | ||
ncu_update(project_directory, commit_message, base_directory) | ||
elif project_directory: | ||
projects_update(project_directory, ignored_dependencies, commit_message, base_directory) | ||
|
||
except KeyboardInterrupt: | ||
print(gitman) | ||
print('\nGitman execution interrupted; exiting.') | ||
sys.exit(0) | ||
|
||
except Exception as e: | ||
print(f"Erro: {e}") | ||
sys.exit(1) | ||
|
||
if __name__ == "__main__": | ||
app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
en: | ||
entering_directory: "Entering directory: %{fullpath}" | ||
running_outdated: "Running 'outdated' in %{fullpath}" | ||
error: "Error checking outdated dependencies in %{fullpath}:" | ||
complete_check: "Check completed." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pt: | ||
entering_directory: "Entrando no diretório: %{fullpath}" | ||
running_outdated: "Rodando 'outdated' em %{fullpath}" | ||
error: "Erro ao verificar dependências desatualizadas em %{fullpath}:" | ||
complete_check: "Verificação concluída." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
en: | ||
entering_directory: "Entering directory: %{fullpath}" | ||
checking_git_status: "Checking Git status in %{fullpath}" | ||
git_error: "Error checking Git status in %{fullpath}:" | ||
complete_status: "Git status check completed." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pt: | ||
entering_directory: "Entrando no diretório: %{fullpath}" | ||
checking_git_status: "Verificando o status do Git em %{fullpath}" | ||
git_error: "Erro ao verificar o status do Git em %{fullpath}:" | ||
complete_status: "Verificação de status do Git concluída." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
en: | ||
version: "Program version: %{version}" | ||
version_not_found: "Version not found" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pt: | ||
version: "Versão do programa: %{version}" | ||
version_not_found: "Versão desconhecida" |
Oops, something went wrong.