mirror of
https://github.com/yann64/haikuports.git
synced 2026-04-09 05:10:05 +02:00
333 lines
11 KiB
Plaintext
333 lines
11 KiB
Plaintext
From af99265c4bd9c2014525942c14424af2182cccf4 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
|
|
|
|
|
|
diff --git a/haiku_cnf.py b/haiku_cnf.py
|
|
index 7c68057..c7f51d9 100644
|
|
--- a/haiku_cnf.py
|
|
+++ b/haiku_cnf.py
|
|
@@ -17,7 +17,7 @@ def update_db():
|
|
db['base-pkgs'] = json.dumps(read_basepkgs())
|
|
if Popen(['which', 'haikuporter'],stdout=PIPE).communicate()[0]:
|
|
home = os.path.expanduser('~')
|
|
- with open("%s/config/settings/command-not-found/options.json" % home, "w") as options:
|
|
+ with open("%s/config/settings/command-not-found/options.json" % home, "rw") as options:
|
|
d = json.load(options)
|
|
d['haikuports'] = True
|
|
# json.dump(d, options)
|
|
diff --git a/install_cnf.py b/install_cnf.py
|
|
index 1e1dd35..fc0051b 100644
|
|
--- a/install_cnf.py
|
|
+++ b/install_cnf.py
|
|
@@ -35,7 +35,6 @@ def main():
|
|
options = open("%s/config/settings/command-not-found/options.json" % home, "w")
|
|
options.write(default_options)
|
|
options.close()
|
|
- os.system("install -m 755 haiku_cnf.py /boot/system/non-packaged/bin/command_not_found.py")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
--
|
|
2.37.3
|
|
|
|
|
|
From 8ac41f59adfcd610544e0583745d5103f141abaa 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
|
|
|
|
|
|
diff --git a/haiku_cnf.py b/haiku_cnf.py
|
|
index c7f51d9..d9e0644 100644
|
|
--- a/haiku_cnf.py
|
|
+++ b/haiku_cnf.py
|
|
@@ -1,6 +1,7 @@
|
|
#!/bin/env python
|
|
#GPL v3 (c) 2011, 2016-2017 Jack Laxson "jrabbit"
|
|
import anydbm
|
|
+import commands
|
|
import json
|
|
import os
|
|
import pprint
|
|
@@ -106,6 +107,26 @@ def our_help():
|
|
--
|
|
%(app)s reads options from ~/config/settings/command-not-found/options.json""" % {'app': sys.argv[0]}
|
|
|
|
+
|
|
+
|
|
+def write_default_opt():
|
|
+ default_options="""{
|
|
+"autocorrect": false,
|
|
+"spellcheck": false,
|
|
+"haikuports": false
|
|
+}\n"""
|
|
+
|
|
+ home = commands.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)
|
|
+ except OSError:
|
|
+ # Folder exists
|
|
+ pass
|
|
+ options = open("%s/command-not-found/options.json" % home, "w")
|
|
+ options.write(default_options)
|
|
+ options.close()
|
|
+
|
|
def cnf(command):
|
|
logger.debug("Entered CNF: %s", command)
|
|
db = get_db()
|
|
@@ -131,6 +152,7 @@ if __name__ == '__main__':
|
|
sys.exit()
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
command = sys.argv[1]
|
|
+ write_default_opt()
|
|
options = get_options()
|
|
if 'meta-setup' not in get_db():
|
|
logger.debug("Running for first time")
|
|
--
|
|
2.37.3
|
|
|
|
|
|
From 72cb67f6d656f95a77135bbaec335254cf5100ef 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 96ec2cc13f6b46a7f22b526cc476811a759ac0a2 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 ae2640725537f3b500188db7b85dcf6b49d8ca98 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 15575933aa916b203ad307c15ca2a4251ecd3aa7 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 d8877dd8a78678637d54b07ac45a3a3dfc9bf9bc 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..9e765ec 100644
|
|
--- a/haiku_cnf.py
|
|
+++ b/haiku_cnf.py
|
|
@@ -135,15 +135,15 @@ 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))
|
|
+ print('I found multiple potential packages for "{}"'.format(command))
|
|
+ print('Try one of these: "{}"'.format(provides_info))
|
|
else:
|
|
print("{} : Command not found. Sorry.".format(command))
|
|
|
|
--
|
|
2.37.3
|
|
|
|
|
|
From b081c20bba94df134a4336542effe45011f7e64e Mon Sep 17 00:00:00 2001
|
|
From: Oscar Lesta <oscar.lesta@gmail.com>
|
|
Date: Mon, 25 Sep 2023 03:58:18 -0300
|
|
Subject: Use unitest.mock from Python's stdlib.
|
|
|
|
|
|
diff --git a/test_cnf.py b/test_cnf.py
|
|
index 7ab8416..2ce98e3 100644
|
|
--- a/test_cnf.py
|
|
+++ b/test_cnf.py
|
|
@@ -1,5 +1,5 @@
|
|
import unittest
|
|
-import mock
|
|
+from unittest import mock
|
|
|
|
from haiku_cnf import search_provides, read_haikuports, firstrun
|
|
|
|
--
|
|
2.37.3
|
|
|