Skip to content

Commit

Permalink
refactory folders
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasferreiralimax committed Jun 24, 2024
1 parent 9e7ca08 commit eea0520
Show file tree
Hide file tree
Showing 20 changed files with 28 additions and 46 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
68 changes: 26 additions & 42 deletions src/main.py → gitman/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,27 @@
import os
import sys
import i18n
import platform
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
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

# 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
import subprocess

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
import subprocess

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('translations')
i18n.set('fallback', 'en')
i18n.set('locale', system_lang)
gitman = """
_______ __ .___________..___ ___. ___ .__ __.
/ _____|| | | || \/ | / \ | \ | |
| | __ | | `---| |----`| \ / | / ^ \ | \| |
| | |_ | | | | | | |\/| | / /_\ \ | . ` |
| |__| | | | | | | | | | / _____ \ | |\ |
\______| |__| |__| |__| |__| /__/ \__\ |__| \__|
"""

# Função para exibir o uso correto do script
def usage():
print(i18n.t('main.usage.description', name=sys.argv[0]))
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))
Expand All @@ -54,6 +31,8 @@ def usage():
# Função principal do programa
def app():
try:
i18nConfig()

# Verifica os parâmetros do script
if len(sys.argv) == 1:
usage()
Expand Down Expand Up @@ -95,9 +74,14 @@ def app():
elif project_directory:
projects_update(project_directory, ignored_dependencies, commit_message, base_directory)

except KeyboardInterrupt:
print(i18n.t('main.interrupted'))
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()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions translations/main.en.yml → gitman/translations/main.en.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
en:
usage:
description: "Usage: %{name} [-b <base_directory>] [-u <project_directory>] [-i <ignored_dependencies>] [-a] [-g] [-n <project_directory>] [-m <commit_message>]"
description: "Usage: gitman [-b <base_directory>] [-u <project_directory>] [-i <ignored_dependencies>] [-a] [-g] [-n <project_directory>] [-m <commit_message>]"
line1: "-b <base_directory> Base directory where projects are located. (default: ~/Documents)"
line2: "-u <project_directory> Updates the dependencies of the specified project directory."
line3: " If multiple projects are provided, separate them with a comma."
Expand All @@ -10,4 +10,3 @@ en:
line7: "-n <project_directory> Runs npx npm-check-updates -u && npm install followed by a commit."
line8: "-m <commit_message> Commit message to be used in updates. (optional)"
line9: "-v, --version Shows the program version."
interrupted: "\nScript execution interrupted."
3 changes: 1 addition & 2 deletions translations/main.pt.yml → gitman/translations/main.pt.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pt:
usage:
description: "Uso: %{name} [-b <base_directory>] [-u <project_directory>] [-i <ignored_dependencies>] [-a] [-g] [-n <project_directory>] [-m <commit_message>]"
description: "Uso: gitman [-b <base_directory>] [-u <project_directory>] [-i <ignored_dependencies>] [-a] [-g] [-n <project_directory>] [-m <commit_message>]"
line1: "-b <base_directory> Diretório base onde os projetos estão localizados. (padrão: ~/Documents)"
line2: "-u <project_directory> Atualiza as dependências do diretório de projeto especificado."
line3: " Se múltiplos projetos forem fornecidos, separe-os por vírgula."
Expand All @@ -10,4 +10,3 @@ pt:
line7: "-n <project_directory> Roda npx npm-check-updates -u && npm install seguido de um commit."
line8: "-m <commit_message> Mensagem de commit a ser usada nas atualizações. (opcional)"
line9: "-v, --version Mostra a versão do programa."
interrupted: "\nExecução do script interrompida."
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit eea0520

Please sign in to comment.