mirror of
https://github.com/yann64/haikuports.git
synced 2026-04-23 12:10:06 +02:00
command_not_found: switch to Python 3.9. (#8497)
* Added TEST() * Added a couple of minor fixes here and there.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
From 192f2f912f75b7304f09f2b255e24427eef800c1 Mon Sep 17 00:00:00 2001
|
||||
From 9dd9d0084cfb2f3526d0f5e6c33ad944e1b197ec Mon Sep 17 00:00:00 2001
|
||||
From: tts2k <tranthaison2000@gmail.com>
|
||||
Date: Sun, 7 Jan 2018 02:49:19 +0000
|
||||
Subject: Add read permission
|
||||
@@ -30,10 +30,10 @@ index 1e1dd35..fc0051b 100644
|
||||
|
||||
if __name__ == '__main__':
|
||||
--
|
||||
2.15.0
|
||||
2.37.3
|
||||
|
||||
|
||||
From b0ab9db5c1938def17e0785eb03fb709c060dbfe Mon Sep 17 00:00:00 2001
|
||||
From 8fd2339e220b14e4402d3098ed9bc797244bc605 Mon Sep 17 00:00:00 2001
|
||||
From: tts2k <tranthaison2000@gmail.com>
|
||||
Date: Tue, 9 Jan 2018 12:27:13 +0000
|
||||
Subject: write default option if not available
|
||||
@@ -87,5 +87,220 @@ index c7f51d9..d9e0644 100644
|
||||
if 'meta-setup' not in get_db():
|
||||
logger.debug("Running for first time")
|
||||
--
|
||||
2.15.0
|
||||
2.37.3
|
||||
|
||||
|
||||
From 3d0031ec35ff3491d13205b79250e75476fe09b3 Mon Sep 17 00:00:00 2001
|
||||
From: Oscar Lesta <oscar.lesta@gmail.com>
|
||||
Date: Sun, 23 Apr 2023 15:15:02 -0300
|
||||
Subject: Switch to Python3
|
||||
|
||||
|
||||
diff --git a/haiku_cnf.py b/haiku_cnf.py
|
||||
index d9e0644..23e2179 100644
|
||||
--- a/haiku_cnf.py
|
||||
+++ b/haiku_cnf.py
|
||||
@@ -1,7 +1,7 @@
|
||||
-#!/bin/env python
|
||||
+#!python3
|
||||
#GPL v3 (c) 2011, 2016-2017 Jack Laxson "jrabbit"
|
||||
-import anydbm
|
||||
-import commands
|
||||
+import dbm
|
||||
+import subprocess
|
||||
import json
|
||||
import os
|
||||
import pprint
|
||||
@@ -27,12 +27,13 @@ def update_db():
|
||||
def get_db(name="filenames"):
|
||||
home = os.path.expanduser('~')
|
||||
directory = os.path.join(home,"config", "settings","command-not-found")
|
||||
- return anydbm.open(os.path.join(directory, name), 'c')
|
||||
+ return dbm.open(os.path.join(directory, name), 'c')
|
||||
|
||||
def all_cmds():
|
||||
db = get_db()
|
||||
cmds = []
|
||||
for x in db:
|
||||
+ x = x.decode('utf-8')
|
||||
if x.split('-')[0] not in ['haikuports', 'meta']:
|
||||
cmds = cmds + json.loads(db[x])
|
||||
return cmds
|
||||
@@ -45,7 +46,7 @@ def get_options():
|
||||
return json.load(f)
|
||||
|
||||
def search_provides(cmd):
|
||||
- out = check_output(['pkgman', 'search', '--details', 'cmd:{}'.format(cmd)])
|
||||
+ out = check_output(['pkgman', 'search', '--details', 'cmd:{}'.format(cmd)]).decode('utf-8')
|
||||
split = out.splitlines()
|
||||
if out.startswith("No matching packages found."):
|
||||
return None
|
||||
@@ -54,14 +55,14 @@ def search_provides(cmd):
|
||||
return [{"name": i.split()[1], "repo":i.split()[0]} for i in rest]
|
||||
|
||||
def read_pkgman():
|
||||
- out = check_output(['pkgman', 'search', '-a', '--details'])
|
||||
+ out = check_output(['pkgman', 'search', '-a', '--details']).decode('utf-8')
|
||||
rest = out.splitlines()[2:]
|
||||
return [i.split()[1] for i in rest]
|
||||
|
||||
def read_basepkgs():
|
||||
baseapps = []
|
||||
for x in os.environ['PATH'].split(':'):
|
||||
- if x is not ".": #Why the hell is this in $PATH?
|
||||
+ if x != ".": #Why the hell is this in $PATH?
|
||||
try:
|
||||
baseapps = baseapps + os.listdir(x)
|
||||
except OSError:
|
||||
@@ -70,7 +71,7 @@ def read_basepkgs():
|
||||
return baseapps
|
||||
|
||||
def read_haikuports():
|
||||
- return check_output(["haikuporter", "-l"]).splitlines()
|
||||
+ return check_output(["haikuporter", "-l"]).decode('utf-8').splitlines()
|
||||
|
||||
def firstrun():
|
||||
"""Cache existing packages for later use"""
|
||||
@@ -111,12 +112,12 @@ def our_help():
|
||||
|
||||
def write_default_opt():
|
||||
default_options="""{
|
||||
-"autocorrect": false,
|
||||
+"autocorrect": false,
|
||||
"spellcheck": false,
|
||||
"haikuports": false
|
||||
}\n"""
|
||||
|
||||
- home = commands.getoutput('finddir B_USER_SETTINGS_DIRECTORY')
|
||||
+ home = subprocess.getoutput('finddir B_USER_SETTINGS_DIRECTORY')
|
||||
if not os.path.exists("%s/command-not-found/options.json" % home):
|
||||
try:
|
||||
os.mkdir("%s/command-not-found/" % home)
|
||||
--
|
||||
2.37.3
|
||||
|
||||
|
||||
From 36c7f10ba246de1913f2aaf63ce6c1091ed5a1d8 Mon Sep 17 00:00:00 2001
|
||||
From: Oscar Lesta <oscar.lesta@gmail.com>
|
||||
Date: Sun, 23 Apr 2023 16:19:31 -0300
|
||||
Subject: Shut up already!
|
||||
|
||||
|
||||
diff --git a/haiku_cnf.py b/haiku_cnf.py
|
||||
index 23e2179..304b2fa 100644
|
||||
--- a/haiku_cnf.py
|
||||
+++ b/haiku_cnf.py
|
||||
@@ -151,7 +151,7 @@ if __name__ == '__main__':
|
||||
if len(sys.argv) < 2 or sys.argv[1] in ['-h', '--help']:
|
||||
print(our_help())
|
||||
sys.exit()
|
||||
- logging.basicConfig(level=logging.DEBUG)
|
||||
+ logging.basicConfig(level=logging.INFO)
|
||||
command = sys.argv[1]
|
||||
write_default_opt()
|
||||
options = get_options()
|
||||
--
|
||||
2.37.3
|
||||
|
||||
|
||||
From 6cd502dedca16845ac2e908022a5f3dcfb2c88dc Mon Sep 17 00:00:00 2001
|
||||
From: Oscar Lesta <oscar.lesta@gmail.com>
|
||||
Date: Sun, 23 Apr 2023 16:22:32 -0300
|
||||
Subject: Use quotes around the suggested command
|
||||
|
||||
|
||||
diff --git a/haiku_cnf.py b/haiku_cnf.py
|
||||
index 304b2fa..f8bd459 100644
|
||||
--- a/haiku_cnf.py
|
||||
+++ b/haiku_cnf.py
|
||||
@@ -178,7 +178,7 @@ if __name__ == '__main__':
|
||||
sys.exit()
|
||||
else:
|
||||
# So when we get here we should still say CNF right?
|
||||
- print("Did you mean %s" % word)
|
||||
+ print('Did you mean "%s"' % word)
|
||||
cnf(command)
|
||||
# Need to escape the for loop
|
||||
sys.exit()
|
||||
--
|
||||
2.37.3
|
||||
|
||||
|
||||
From e4c10ec446113ee64c853ff0065b9ee38e9694fd Mon Sep 17 00:00:00 2001
|
||||
From: Oscar Lesta <oscar.lesta@gmail.com>
|
||||
Date: Sun, 23 Apr 2023 16:37:16 -0300
|
||||
Subject: Fix tests for Python3
|
||||
|
||||
|
||||
diff --git a/test_cnf.py b/test_cnf.py
|
||||
index 0183a5e..7ab8416 100644
|
||||
--- a/test_cnf.py
|
||||
+++ b/test_cnf.py
|
||||
@@ -8,12 +8,14 @@ class TestPkgmanHooks(unittest.TestCase):
|
||||
def test_search_provides(self, patched_check_output):
|
||||
pkgman_out = """Status Name Description
|
||||
-----------------------------------------------------------------------------
|
||||
- postgresql A powerful, open source object-relational database system"""
|
||||
+ postgresql A powerful, open source object-relational database system""".encode()
|
||||
+
|
||||
# > pkgman search postgre -D
|
||||
pkgman_details = """Repository Name Version Arch
|
||||
-----------------------------------------------------
|
||||
HaikuPorts postgresql 9.3.5-2 x86_gcc2
|
||||
-"""
|
||||
+""".encode()
|
||||
+
|
||||
patched_check_output.return_value = pkgman_details
|
||||
ret = search_provides("pg")
|
||||
# expected = {'status': False, 'name': 'postgresql', 'description': "A powerful, open source object-relational database system"}
|
||||
@@ -22,7 +24,7 @@ HaikuPorts postgresql 9.3.5-2 x86_gcc2
|
||||
|
||||
@mock.patch('haiku_cnf.check_output')
|
||||
def test_search_provides_bogus(self, patched_check_output):
|
||||
- patched_check_output.return_value = "No matching packages found."
|
||||
+ patched_check_output.return_value = "No matching packages found.".encode()
|
||||
ret = search_provides("foobarbaz")
|
||||
expected = None
|
||||
self.assertEqual(ret, expected)
|
||||
@@ -32,7 +34,7 @@ class TestHP(unittest.TestCase):
|
||||
@mock.patch('haiku_cnf.check_output')
|
||||
def test_haikuports(self, patched_check_output):
|
||||
ret = read_haikuports()
|
||||
- patched_check_output.return_value.splitlines.assert_called_with()
|
||||
+ patched_check_output.return_value.decode('utf-8').splitlines.assert_called_with()
|
||||
|
||||
|
||||
class TestFirstRun(unittest.TestCase):
|
||||
--
|
||||
2.37.3
|
||||
|
||||
|
||||
From c1608ba6cc01dddae53d2520a3bd77571cd1060c Mon Sep 17 00:00:00 2001
|
||||
From: Oscar Lesta <oscar.lesta@gmail.com>
|
||||
Date: Sun, 23 Apr 2023 17:10:20 -0300
|
||||
Subject: More quotation fixes, some spellchecking too.
|
||||
|
||||
|
||||
diff --git a/haiku_cnf.py b/haiku_cnf.py
|
||||
index f8bd459..2c519d3 100644
|
||||
--- a/haiku_cnf.py
|
||||
+++ b/haiku_cnf.py
|
||||
@@ -135,12 +135,12 @@ def cnf(command):
|
||||
if options['haikuports'] == True:
|
||||
logger.debug("CNF: Haikuports check")
|
||||
if command in json.loads(db['haikuports']):
|
||||
- print("This application is availible via `haikuporter -i %s`" % command)
|
||||
+ print('This application is available via "haikuporter -i %s"' % command)
|
||||
elif command in json.loads(db['haikudepot']):
|
||||
- print("This application is aviaiblible via pkgman install {}".format(command))
|
||||
+ print('This application is available via pkgman install {}"'.format(command))
|
||||
elif provides_info:
|
||||
if len(provides_info) == 1:
|
||||
- print("This application is aviaiblible via pkgman install {}".format(command))
|
||||
+ print('This application is available via "pkgman install {}"'.format(command))
|
||||
else:
|
||||
print("I found multiple potential packages for {}".format(command))
|
||||
print("Try one of these: {}".format(provides_info))
|
||||
--
|
||||
2.37.3
|
||||
|
||||
|
||||
Reference in New Issue
Block a user