mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-15 03:53:32 +01:00
build.cmds.GetAuthInfo: Add module
Add command get-auth-info to jw-projects.py. It is meant to retrieve JANWARE_USER from an already cloned jw-build tree. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
8de4a90796
commit
1187c10c86
1 changed files with 38 additions and 0 deletions
38
src/python/jw/build/cmds/CmdGetAuthInfo.py
Normal file
38
src/python/jw/build/cmds/CmdGetAuthInfo.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import re
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from ..Cmd import Cmd
|
||||
from ..lib.util import run_cmd
|
||||
|
||||
class CmdGetAuthInfo(Cmd): # export
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__('get-auth-info', help='Try to retrieve authentication information from the source tree')
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('--only-values', help='Don\'t prefix values by "<field-name>="', action='store_true', default=False)
|
||||
parser.add_argument('--username', help='Show user name', action='store_true', default=False)
|
||||
parser.add_argument('--password', help='Show password', action='store_true', default=False)
|
||||
|
||||
def _run(self, args: Namespace) -> None:
|
||||
remotes = run_cmd(['git', '-C', self.app.proj_dir('jw-build'), 'remote', '-v'])
|
||||
result: dict[str, str] = {}
|
||||
keys = ['username', 'password']
|
||||
for line in remotes.split('\n'):
|
||||
if re.match(r'^\s*$', line):
|
||||
continue
|
||||
name, url, typ = re.split(r'\s+', line)
|
||||
if name == 'origin' and typ == '(push)':
|
||||
parsed = urlparse(url)
|
||||
for key in keys:
|
||||
result[key] = getattr(parsed, key)
|
||||
break
|
||||
for key in keys:
|
||||
if key in result and getattr(args, key, None):
|
||||
if not args.only_values:
|
||||
print(f'{key}=', end='')
|
||||
print(result[key])
|
||||
Loading…
Add table
Add a link
Reference in a new issue