-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for dnf Add references to DNF to README.md * move backend specific flags to install_packages() * Cleanup DNF support
- Loading branch information
Showing
5 changed files
with
108 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import opi.config as config | ||
|
||
class BackendConstants: | ||
zypp = "zypp" | ||
dnf = "dnf" | ||
|
||
|
||
def get_backend(): | ||
backend = config.get_key_from_config("backend") | ||
if not backend in ["zypp", "dnf"]: | ||
raise config.ConfigError("Invalid backend configuration.") | ||
return backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
import pwd | ||
import subprocess | ||
import json | ||
|
||
cache = {} | ||
|
||
class ConfigError(Exception): | ||
pass | ||
|
||
def create_default_config(): | ||
path = pwd.getpwuid(os.getuid()).pw_dir + "/.config/opi/" | ||
subprocess.call(["mkdir", "-p", path]) | ||
config = { | ||
"backend": "zypp" | ||
} | ||
config_file = open(path + 'config.json', 'w') | ||
json.dump(config, config_file, indent=4) | ||
|
||
def get_key_from_config(key: str): | ||
if not key in cache: | ||
path = pwd.getpwuid(os.getuid()).pw_dir + "/.config/opi/config.json" | ||
if not os.path.isfile(path): | ||
create_default_config() | ||
config = json.loads(open(path).read()) | ||
cache[key] = config[key] | ||
return cache[key] | ||
else: | ||
return cache[key] | ||
|
||
path = pwd.getpwuid(os.getuid()).pw_dir + "/.config/opi/config.json" | ||
if not os.path.isfile(path): | ||
create_default_config() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters