Skip to content

Commit

Permalink
2.3.0 dev (#111)
Browse files Browse the repository at this point in the history
* Get started on 2.3.0-dev

* Migrate bh to use click and remove pyCLI

- Should allow for Python 3.10+ and address Issue #109

* Revert "Removing python 3.10 support from install script"

- Should be able to support 3.10 now that pyCLI is removed.

This reverts commit 2e1111d.

* Update workflow to use Python 3.10

* Prepare for release 2.3.0
  • Loading branch information
rcaloras authored Jul 18, 2022
1 parent ca69322 commit 313fa09
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "2.7"]
python-version: ["3.10", "2.7"]

env:
functional_test: true
Expand Down
152 changes: 57 additions & 95 deletions bashhub/bh.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,76 @@
#!/usr/bin/python

from __future__ import print_function
import json
import click
import sys
import requests
from requests import ConnectionError
from builtins import input
import cli.app
import os
import io
import os
import traceback
import datetime

from .model import MinCommand
from builtins import input
from .bashhub_globals import *
from . import rest_client
from .i_search import InteractiveSearch
from .version import version_str
from builtins import str as text

from future.utils import raise_with_traceback
@click.command()
@click.argument('query', type=str, default='')
@click.option('-n', '--number', default=None, help='Limit the number of previous commands. Default is 100.', type=int)
@click.option("-ses",
"--session",
help="Filter by specific session id. Default is None.",
default=None,
type=str)
@click.option("-d",
"--directory",
help="Search for commands within this directory.",
default=False,
is_flag=True)
@click.option("-sys",
"--system",
help="Search for commands created on this system.",
default=False,
is_flag=True)
@click.option("-i",
"--interactive",
help="Use interactive search. Allows you to select commands to run.",
default=False,
is_flag=True)
@click.option("-dups",
"--duplicates",
help="Include duplicates",
default=False,
is_flag=True)
@click.option("-t",
"--timestamps",
help="Include timestamps",
default=False,
is_flag=True)
@click.option("-V",
"--version",
help="Print version information",
default=False,
is_flag=True)
def bh(query, number, session, directory, system, interactive, duplicates, timestamps, version):
"""Bashhhub Search
def post_run_exception_handling(returned):
# Override PyCLI post_run method to support Python 3 and 2
if isinstance(returned, Exception):
if (sys.version_info > (3, 0)):
raise returned
else:
raise_with_traceback(returned)
else:
sys.exit(0)

@cli.app.CommandLineApp
def bh(app):
"""Bashhub Search"""
app.post_run = post_run_exception_handling
limit = app.params.number
query = app.params.query
system_name = BH_SYSTEM_NAME if app.params.system else None
path = os.getcwd() if app.params.directory else None
session_id = app.params.session
QUERY - Like string to search for
"""
limit = number
system_name = BH_SYSTEM_NAME if system else None
path = os.getcwd() if directory else None
session_id = session

# By default show unique on the client.
unique = not app.params.duplicates
unique = not duplicates

use_timestamps = app.params.timestamps
use_timestamps = timestamps

# If we're interactive, make sure we have a query
if app.params.interactive and query == '':
if interactive and query == '':
query = input("(bashhub-i-search): ")

if app.params.version and query == '':
if version and query == '':
print(version_str)
sys.exit()

Expand All @@ -62,7 +82,7 @@ def bh(app):
unique=unique,
session_id=session_id)

if app.params.interactive:
if interactive:
run_interactive(commands)
else:
print_commands(commands, use_timestamps)
Expand All @@ -87,79 +107,21 @@ def run_interactive(commands):
f = io.open(BH_HOME + '/response.bh', 'w+', encoding='utf-8')
print(text(command.command), file=f)


def unix_milliseconds_timestamp_to_datetime(timestamp):
return datetime.datetime.fromtimestamp(int(timestamp) / 1000) \
.strftime('%Y-%m-%d %H:%M:%S')


bh.add_param("-n",
"--number",
help="Limit the number of previous commands. Default is 100.",
default=None,
type=int)

bh.add_param("-ses",
"--session",
help="Filter by specific session id. Default is None.",
default=None,
type=str)

bh.add_param("query",
nargs='?',
help="Like string to search for",
default="",
type=str)

bh.add_param("-d",
"--directory",
help="Search for commands within this directory.",
default=False,
action='store_true')

bh.add_param("-sys",
"--system",
help="Search for commands created on this system.",
default=False,
action='store_true')

bh.add_param(
"-i",
"--interactive",
help="Use interactive search. Allows you to select commands to run.",
default=False,
action='store_true')

bh.add_param("-dups",
"--duplicates",
help="Include duplicates",
default=False,
action='store_true')

bh.add_param("-t",
"--timestamps",
help="Include timestamps",
default=False,
action='store_true')

bh.add_param("-V",
"--version",
help="Print version information",
default=False,
action='store_true')

def main():
try:
bh.run()
bh()
except Exception as e:
if BH_DEBUG:
traceback.print_exc()
print("Oops, look like an exception occured: " + str(e))
click.echo("Oops, look like an exception occured: " + str(e))
sys.exit(1)
except KeyboardInterrupt:
# To allow Ctrl+C (^C). Print a new line to drop the prompt.
print()
click.echo()
sys.exit()


main()
2 changes: 1 addition & 1 deletion bashhub/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import platform

__version__ = '2.2.0'
__version__ = '2.3.0'

version_str = 'Bashhub {0} (python {1})'.format(__version__, platform.python_version())
5 changes: 3 additions & 2 deletions install-bashhub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fi

PYTHON_VERSION_COMMAND='
import sys
if (3, 5, 0) < sys.version_info < (3, 10, 0):
if (3, 5, 0) < sys.version_info < (3, 11, 0):
sys.exit(0)
elif (2, 7, 8) < sys.version_info < (3,0):
sys.exit(0)
Expand All @@ -49,6 +49,7 @@ else:
PYTHON_VERSION_ARRAY=(
"/usr/bin/python3"
"python3"
"python3.10"
"python3.9"
"python3.8"
"python3.7"
Expand All @@ -67,7 +68,7 @@ fish_config="${XDG_CONFIG_HOME:-~/.config}/fish/config.fish"

# Optional parameter to specify a github branch
# to pull from.
github_branch=${1:-'2.2.0'}
github_branch=${1:-'2.3.0'}

install_bashhub() {
check_dependencies
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
include_package_data=True,
install_requires=[
'requests==2.23.0', 'jsonpickle==2.0.0', 'click==6.7',
'npyscreen==4.10.5', 'python-dateutil==2.8.1', 'pyCLI==2.0.3',
'npyscreen==4.10.5', 'python-dateutil==2.8.1',
'pymongo==3.10.1', 'inflection==0.3.1', 'humanize==1.0.0',
'future==0.18.2', 'mock==3.0.5'
],
Expand Down
7 changes: 4 additions & 3 deletions tests/shell/install-bashhub.bats
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,22 @@ setup() {
[[ $status == 0 ]]
}

@test "get_and_check_python_version should find python3.9 first" {
@test "get_and_check_python_version should find python3.10 first" {
# Mock up some fake responses here.
/usr/bin/python3() { return 1; }
python3() { return 1; }
python3.9() { return 0; }
python3.10() { return 0; }

run 'get_and_check_python_version'
[[ $status == 0 ]]
[[ "$output" == "python3.9" ]]
[[ "$output" == "python3.10" ]]
}

@test "get_and_check_python_version should find different python versions" {
# Mock up some fake responses here.
/usr/bin/python3() { return 1; }
python3() { return 1; }
python3.10() { return 1; }
python3.9() { return 1; }
python3.8() { return 1; }
python3.7() { return 1; }
Expand Down

0 comments on commit 313fa09

Please sign in to comment.