Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mimic wstool info output #246

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
aebd5e2
Add new repos command to give report similar to wstool output. One li…
tdenewiler Apr 6, 2022
83979c3
Black formatting.
tdenewiler Apr 6, 2022
d60783b
Remove Python 3.5, 3.6 from test environment.
tdenewiler Apr 6, 2022
09ce4f1
Nicely print out results for repos command.
tdenewiler Apr 7, 2022
23e2f76
Handle result output functions with varying number of arguments.
tdenewiler Apr 7, 2022
e1a7952
Allow manual trigger of workflows. Add newer Python versions to Ubunt…
tdenewiler Sep 2, 2022
11e7794
Fix syntax for Python versions.
tdenewiler Sep 2, 2022
786c87c
Pin version of flake8 to less than 5 to fix upstream bug.
tdenewiler Sep 2, 2022
041636c
Switch to requirements.txt for dependencies to better support pinning…
tdenewiler Sep 2, 2022
d74152a
Add repos support for hg, svn, and bzr clients.
tdenewiler Oct 12, 2022
8927f91
Update bzr client for repos command, almost working.
tdenewiler Oct 12, 2022
57b0340
Set default values for bzr client and fill in if available.
tdenewiler Oct 12, 2022
bfe1389
bzr client works in trunk of repo but not anywhere else in workspace.…
tdenewiler Oct 12, 2022
20fb668
Improve discovery of bzr URL field.
tdenewiler Oct 19, 2022
5f94c26
Code style cleanup and tests passing.
tdenewiler Oct 19, 2022
0eb8487
Simplify printing repos results by using the tabulate package.
tdenewiler Oct 26, 2022
2f95e9b
Add tabulate package to required installs.
tdenewiler Oct 26, 2022
ef622de
Fix flake8 warnings.
tdenewiler Oct 26, 2022
b7144fa
Install tabulate as part of CI workflow.
tdenewiler Oct 26, 2022
d7aa3ee
Revert "Install tabulate as part of CI workflow."
tdenewiler Jan 3, 2023
3cd63bc
Revert "Fix flake8 warnings."
tdenewiler Jan 3, 2023
0d57265
Revert "Add tabulate package to required installs."
tdenewiler Jan 3, 2023
16d9309
Revert "Simplify printing repos results by using the tabulate package."
tdenewiler Jan 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:

jobs:
build:
Expand All @@ -12,7 +13,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.5, 3.6, 3.7, 3.8]
python-version: ['3.7', '3.8', '3.9', '3.10']
include:
- os: macos-latest
python-version: 3.8
Expand All @@ -35,7 +36,7 @@ jobs:
if: matrix.os == 'macos-latest'
- name: Test with pytest
run: |
pip install --upgrade coverage flake8 flake8-docstrings flake8-import-order pytest
pip install --upgrade -r requirements.txt
git config --global --add init.defaultBranch master
git config --global --add advice.detachedHead true
${{ matrix.os == 'windows-latest' && 'set PYTHONPATH=%cd% &&' || 'PYTHONPATH=`pwd`' }} pytest -s -v test
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage
flake8-docstrings
flake8-import-order
flake8<5
pytest
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
'vcs-pull = vcstool.commands.pull:main',
'vcs-push = vcstool.commands.push:main',
'vcs-remotes = vcstool.commands.remotes:main',
'vcs-repos = vcstool.commands.repos:main',
'vcs-status = vcstool.commands.status:main',
'vcs-svn = vcstool.commands.custom:svn_main',
'vcs-validate = vcstool.commands.validate:main',
Expand Down
2 changes: 1 addition & 1 deletion test/commands.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
branch custom diff export import log pull push remotes status validate
branch custom diff export import log pull push remotes repos status validate
45 changes: 45 additions & 0 deletions vcstool/clients/bzr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copy
import os
import pathlib
from shutil import which

from .vcs_base import VcsClientBase
Expand Down Expand Up @@ -168,6 +169,50 @@ def remotes(self, _command):
self._check_executable()
return self._get_parent_branch()

def repos(self, command):
retval = {}
retval["localname"] = 'placeholder'
retval["status"] = '-'
retval["scm"] = 'bzr'
retval["version"] = 'version'
retval["uid"] = 'uid'
retval["uri"] = 'uri'
retval["returncode"] = 1

self._check_executable()
cmd = [BzrClient._executable, 'info']
output = self._run_command(cmd)

if output["output"].startswith('Shared'):
return retval

url = output['output'].split()[12]

cmd = [BzrClient._executable, 'status', '-S']
output = self._run_command(cmd)
localname = pathlib.Path(output["cwd"]).relative_to(pathlib.Path.cwd())
returncode = output['returncode']
if output['output']:
status = output["output"].split()[0].upper()
else:
status = "-"
cmd = [BzrClient._executable, 'version-info']
output = self._run_command(cmd)
version = output['output'].split()[11]
uid = output['output'].split()[1].split('-')[2]
cmd = [BzrClient._executable, 'info']
output = self._run_command(cmd)

retval["localname"] = localname
retval["status"] = status
retval["scm"] = 'bzr'
retval["version"] = version
retval["uid"] = uid
retval["uri"] = url
retval["returncode"] = returncode

return retval

def status(self, _command):
self._check_executable()
cmd = [BzrClient._executable, 'status']
Expand Down
68 changes: 68 additions & 0 deletions vcstool/clients/git.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pathlib
from shutil import which
import subprocess

Expand Down Expand Up @@ -621,6 +622,73 @@ def remotes(self, _command):
cmd = [GitClient._executable, 'remote', '-v']
return self._run_command(cmd)

def repos(self, command):
self._check_executable()
while command.hide_empty:
# check if ahead
cmd = [GitClient._executable, 'log', '@{push}..']
result = self._run_command(cmd)
if not result['returncode'] and result['output']:
# ahead, do not hide
break
# check if behind
cmd = [GitClient._executable, 'log', '..@{upstream}']
result = self._run_command(cmd)
if not result['returncode'] and result['output']:
# behind, do not hide
break
cmd = [GitClient._executable, 'status', '-s']
if command.quiet:
cmd += ['--untracked-files=no']
result = self._run_command(cmd)
if result['returncode'] or not result['output']:
return result
break
cmd = [GitClient._executable, 'status']
self._check_color(cmd)
if command.quiet:
cmd += ['--untracked-files=no']
output = self._run_command(cmd)
localname = pathlib.Path(output["cwd"]).relative_to(pathlib.Path.cwd())
cmd = [GitClient._executable, 'status', '-s']
output = self._run_command(cmd)
# Empty status string means no changes.
status = output["output"]
if status:
status = output["output"].split()[0]
else:
status = "-"
scm = "git"
cmd = [GitClient._executable, 'branch', '--show-current']
output = self._run_command(cmd)
version = output["output"]
if not version:
cmd = [
GitClient._executable,
'describe',
'--tags',
'--exact-match'
]
output = self._run_command(cmd)
version = output["output"]
if version.startswith('fatal: no tag exactly matches'):
version = '<detached>'
cmd = [GitClient._executable, 'rev-parse', 'HEAD']
output = self._run_command(cmd)
uid = output["output"][:12]
cmd = [GitClient._executable, 'config', 'remote.origin.url']
output = self._run_command(cmd)
uri = output["output"]
output["localname"] = localname
output["status"] = status
output["scm"] = scm
output["version"] = version
output["uid"] = uid
output["uri"] = uri
output["returncode"] = 0

return output

def status(self, command):
self._check_executable()
while command.hide_empty:
Expand Down
33 changes: 33 additions & 0 deletions vcstool/clients/hg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pathlib
from shutil import which
from threading import Lock

Expand Down Expand Up @@ -236,6 +237,38 @@ def remotes(self, _command):
cmd = [HgClient._executable, 'paths']
return self._run_command(cmd)

def repos(self, command):
self._check_executable()
cmd = [HgClient._executable, 'status']
self._check_color(cmd)
if command.quiet:
cmd += ['--untracked-files=no']
output = self._run_command(cmd)
localname = pathlib.Path(output["cwd"]).relative_to(pathlib.Path.cwd())
if output['output']:
status = output["output"][0]
else:
status = "-"
result_url = self._get_url()
url = result_url['output']
cmd = [HgClient._executable, 'branch']
output = self._run_command(cmd)
version = output['output']
cmd = [HgClient._executable, 'id']
output = self._run_command(cmd)
uid = output['output'].split()[0]

output = {}
output["localname"] = localname
output["status"] = status
output["scm"] = 'hg'
output["version"] = version
output["uid"] = uid
output["uri"] = url
output["returncode"] = 0

return output

def status(self, command):
self._check_executable()
cmd = [HgClient._executable, 'status']
Expand Down
28 changes: 28 additions & 0 deletions vcstool/clients/svn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pathlib
from shutil import which
from xml.etree.ElementTree import fromstring

Expand Down Expand Up @@ -203,6 +204,33 @@ def remotes(self, _command):
'returncode': 0,
}

def repos(self, command):
self._check_executable()
cmd = [SvnClient._executable, 'status']
if command.quiet:
cmd += ['--quiet']
output = self._run_command(cmd)
localname = pathlib.Path(output["cwd"]).relative_to(pathlib.Path.cwd())
status = output["output"]
if status:
status = output["output"].split()[0]
else:
status = "-"
cmd = [SvnClient._executable, 'info']
output = self._run_command(cmd)
info = output['output'].split()

output = {}
output["localname"] = localname
output["status"] = status
output["scm"] = 'svn'
output["version"] = info[19]
output["uid"] = info[17]
output["uri"] = info[8]
output["returncode"] = 0

return output

def status(self, command):
self._check_executable()
cmd = [SvnClient._executable, 'status']
Expand Down
2 changes: 2 additions & 0 deletions vcstool/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .pull import PullCommand
from .push import PushCommand
from .remotes import RemotesCommand
from .repos import ReposCommand
from .status import StatusCommand
from .validate import ValidateCommand

Expand All @@ -20,6 +21,7 @@
vcstool_commands.append(PullCommand)
vcstool_commands.append(PushCommand)
vcstool_commands.append(RemotesCommand)
vcstool_commands.append(ReposCommand)
vcstool_commands.append(StatusCommand)
vcstool_commands.append(ValidateCommand)

Expand Down
12 changes: 10 additions & 2 deletions vcstool/commands/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

from vcstool.crawler import find_repositories
from vcstool.executor import execute_jobs
from vcstool.executor import execute_jobs, output_result, wstool_info_result
from vcstool.executor import generate_jobs
from vcstool.executor import output_repositories
from vcstool.executor import output_results
Expand All @@ -18,6 +18,7 @@ def __init__(self, args):
self.hide_empty = args.hide_empty if 'hide_empty' in args else False
self.nested = args.nested if 'nested' in args else False
self.output_repos = args.repos if 'repos' in args else False
self.wstool_info = args.wstool_info if 'wstool_info' in args else False
if 'paths' in args:
self.paths = args.paths
else:
Expand Down Expand Up @@ -96,7 +97,14 @@ def simple_main(parser, command_class, args=None):
jobs, show_progress=True, number_of_workers=args.workers,
debug_jobs=args.debug)

output_results(results, hide_empty=args.hide_empty)
output_handler = output_result
if command.wstool_info:
output_handler = wstool_info_result
output_results(
results,
output_handler=output_handler,
hide_empty=args.hide_empty
)

any_error = any(r['returncode'] for r in results)
return 1 if any_error else 0
48 changes: 48 additions & 0 deletions vcstool/commands/repos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import argparse
import sys

from vcstool.streams import set_streams

from .command import Command
from .command import simple_main


class ReposCommand(Command):

command = "repos"
help = "Show repository status per line"

def __init__(self, args):
super(ReposCommand, self).__init__(args)
self.quiet = args.quiet


def get_parser():
parser = argparse.ArgumentParser(
description="Show repository status per line", prog="vcs repos"
)
group = parser.add_argument_group('"repos" command parameters')
group.add_argument(
"-q",
"--quiet",
action="store_true",
default=False,
help="Don't show unversioned items",
)
group.add_argument(
"--wstool_info",
action="store_true",
default=True,
help="Show output in wstool info style",
)
return parser


def main(args=None, stdout=None, stderr=None):
set_streams(stdout=stdout, stderr=stderr)
parser = get_parser()
return simple_main(parser, ReposCommand, args)


if __name__ == "__main__":
sys.exit(main())
Loading