mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-28 11:25:23 +02:00
jw.build.cmds: Move build.cmds -> cmds.projects
Reorganize the Python module structure. Placing the command classes under jw.cmds.projects instead of jw.build.cmds will allow to add a nested command structure, with the current commands, being mostly related to building software, found below a "projects" toplevel command. Other conceivable commands could be "package" for packaging, or "distro" for commands wrapping the distribution's package manager. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
c8c5788aeb
commit
0b83c863a2
43 changed files with 49 additions and 13 deletions
55
src/python/jw/pkg/cmds/projects/CmdGetAuthInfo.py
Normal file
55
src/python/jw/pkg/cmds/projects/CmdGetAuthInfo.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import re, os
|
||||
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)
|
||||
parser.add_argument('--remote-base', help='Show remote base URL', action='store_true', default=False)
|
||||
|
||||
def _run(self, args: Namespace) -> None:
|
||||
keys = ['username', 'password']
|
||||
|
||||
# --- Milk jw-pkg repo
|
||||
jw_pkg_dir = self.app.proj_dir('jw-pkg')
|
||||
if not os.path.isdir(jw_pkg_dir + '/.git'):
|
||||
self.app.debug(f'jw-pkg directory is not a Git repo: {jw_pkg_dir}')
|
||||
return
|
||||
remotes = run_cmd(['git', '-C', jw_pkg_dir, 'remote', '-v'])
|
||||
result: dict[str, str] = {}
|
||||
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 == '(pull)': # TODO: Use other remotes, too?
|
||||
parsed = urlparse(url)
|
||||
for key in keys:
|
||||
result[key] = getattr(parsed, key)
|
||||
base = parsed.geturl()
|
||||
base = re.sub(r'/jw-pkg', '', base)
|
||||
base = re.sub(r'/proj$', '', base)
|
||||
url['remote-base'] = base
|
||||
break
|
||||
|
||||
# --- Print results
|
||||
for key, val in result.items():
|
||||
if getattr(args, key, None) != True:
|
||||
continue
|
||||
if val is None:
|
||||
continue
|
||||
if args.only_values:
|
||||
print(val)
|
||||
continue
|
||||
print(f'{key}="{val}"')
|
||||
Loading…
Add table
Add a link
Reference in a new issue