Hi Leute,
ist das Projekt noch aktuell?
Wenn ja, hätte ich eventuell interesse mitzumachen. Allerdings hätte ich eine kleine Anmerkung:
Bezüglich eures bisher vorhandenen codes solltet ihr mal in PEP 8 reinschauen, hier gibts die deutsche Version:
Python Wiki einfach nach PEP 8 suchen.
Gerade die Namen und die sehr unübliche Einrückung machen es für mich schwer zu lesen.
Hier mal ein schnell zusammengehacktes Beispiel wie die cExec.py (heißt bei mir pacman.py) aussehen könnte:
#!/usr/bin/env python3
"""alpp.pacman
Description
===========
Run pacman commands.
"""
__docformat__ = 'restructuredtext en'
import os
from subprocess import check_output, CalledProcessError
from log import get_logger
PACMAN = '/usr/bin/pacman'
logger = get_logger('pacman')
def is_installed(name):
"""Check if a package is installed on the system.
:parameters:
name : Unicode
Name of the package to check.
:returns: True if the package is installed.
:rtype: Boolean
"""
for app in os.listdir('/var/lib/pacman/local'):
if app.startswith(name):
return True
return False
def run_pacman(cmd):
"""Runs pacman with the given commandline.
:parameters:
cmd : List
Commandlist for pacman.
:returns: None on success, pacman returncode on error.
:rtype: None or Integer
"""
try:
logger.debug('Trying to run %s %s', PACMAN, ' '.join(cmd))
out = check_output(cmd, executable=PACMAN)
logger.info('Command run successfully.')
except CalledProcessError as e:
logger.error('Returncode: %s', e.returncode)
logger.error('Output: %s', e.output)
return e.output
logger.debug('Output: %s', out)
def install_app(*names):
"""Installs the given packages using `run_pacman`.
:parameters:
names : Argumentlist
Each name must be a package.
"""
installed = False
for name in names:
if is_installed(name):
logger.info('%s already installed.', name)
installed = True
if installed:
return
cmd = ['-Sy', '--noconfirm'] + list(names)
out = run_pacman(cmd)
if out is not None:
logger.error('An error occured. See logfile for details.')
def remove_app(*names):
"""Removes the given packages using `run_pacman`.
:parameters:
names : Argumentlist
Each name must be an installed package.
"""
not_installed = False
for name in names:
if not is_installed(name):
logger.info('%s is not installed.', name)
not_installed = True
if not_installed:
return
cmd = ['-R', '--noconfirm'] + list(names)
out = run_pacman(cmd)
if out is not None:
logger.error('An error occured. See logfile for details.')
Wie gesagt, nur schnell nach eurem Beispiel in 10 min geschrieben und so auch nicht lauffähig, da die Datei log.py noch dazu gehört. Wenn jemand interesse hat, kann ich die auch noch posten (ist viel kürzer).
Gruß
Whitie