-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved subprocess method to the helper module
- Loading branch information
Showing
15 changed files
with
122 additions
and
67 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
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
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
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,41 @@ | ||
"""A collection of helper functions""" | ||
import sys | ||
import logging | ||
import subprocess | ||
|
||
logger = logging.getLogger("lnxlink") | ||
|
||
|
||
def syscommand(command): | ||
"""Global subprocess command""" | ||
if isinstance(command, list): | ||
command = " ".join(command) | ||
result = subprocess.run( | ||
command, | ||
shell=True, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
check=False, | ||
timeout=3, | ||
) | ||
stderr = result.stderr.decode("UTF-8").strip() | ||
stdout = result.stdout.decode("UTF-8").strip() | ||
returncode = result.returncode | ||
return stdout, stderr, returncode | ||
|
||
|
||
def import_install_package(package, version="", syspackage=None): | ||
"""Imports a system package and if it doesn't exist, it gets installed""" | ||
if syspackage is None: | ||
syspackage = package | ||
try: | ||
return __import__(syspackage) | ||
except ImportError: | ||
package_version = package + version | ||
logger.error("Package %s is not installed, installing now...", package_version) | ||
args = [sys.executable, "-m", "pip", "install", "--quiet", package_version] | ||
_, stderr, returncode = syscommand(args) | ||
if returncode != 0: | ||
logger.error("Can't install package %s: %s", package, stderr) | ||
return None | ||
return __import__(syspackage) |
Oops, something went wrong.