Critic my module
Joshua Landau
joshua at landau.ws
Thu Jul 25 10:03:55 EDT 2013
On 25 July 2013 14:24, Devyn Collier Johnson <devyncjohnson at gmail.com>wrote:
> Aloha Python Users!
>
> I made a Python3 module that allows users to use certain Linux shell
> commands from Python3 more easily than using os.system(),
> subprocess.Popen(), or subprocess.getoutput(). This module (once placed
> with the other modules) can be used like this
>
> import boash; boash.ls()
>
> I attached the module. I plan to release it on the Internet soon, but
> feel free to use it now. It is licensed under LGPLv3.
>
> The name comes from combining "Boa" with "SHell". Notice that the
> module's name almost looks like "BASH", a common Linux shell. The Boa is a
> constrictor snake. This module makes Unix shells easier to use via Python3.
> This brings the system shell closer to the Python shell.
>
1) Have you tested everything? At first glance some of those look like they
won't work.
2) Whenever you repeat yourself, *especially* at this magnitude, you're
doing something seriously wrong - *especially* in Python.
*Completely-untestedly-and-super-quick-hackedly:*
import re, sys, subprocess, platform
class Command:
def __init__(self, command=None):
self.command = command
def __call__(self, *args):
command_list = [self.command] if self.command else []
command_list.extend(args)
print(subprocess.getoutput([command_list]))
def uname():
print(platform.uname())
def lsof():
print(subprocess.getoutput(lsof))
apropos = Command("apropos")
arora = Command("(arora &)")
dir = Command("dir")
dolphin = Command("(dolphin &)")
env = Command("env")
finger = Command("finger")
firefox = Command("(firefox &)")
free = Command("free")
geany = Command("(geany &)")
getcwd = Command("pwd")
go_back = Command("cd !!:1")
halt = Command("shutdown -h now")
hostname = Command("hostname")
konqueror = Command("(konqueror &)")
ls = Command("ls")
lsof = Command("lsof")
man = Command("man")
mplayer = Command("(mplayer &)")
nautilus = Command("(nautilus &)")
nvlc = Command("(nvlc &)")
opera = Command("(opera &)")
pwd = Command("pwd")
qvlc = Command("(qvlc &)")
repeat = Command("!")
runlevel = Command("runlevel")
rvlc = Command("(rvlc &)")
smplayer = Command("(smplayer &)")
svlc = Command("(svlc &)")
vlc = Command("(vlc &)")
whoami = Command("whoami")
xterm = Command("(xterm &)")
arch = architecture = Command("arch")
bash = cmd = command = shell = Command()
last_cmd = last_command = repeat_cmd = Command("!!")
ll = vdir = Command("ls - l")
no_login = no_logins = nologin = nologins = Command("shutdown -k now")
power_down = power_off = powerdown = poweroff = Command("shutdown -P now")
reboot = restart = Command("shutdown -r now")
shut_down = shutdown = Command("shutdown now")
clear_bash_hist = clear_bash_history = clear_hist = clear_history = \
del_bash_hist = del_hist = delete_bash_hist = delete_bash_history = \
delete_hist = delete_history = Command("history -c")
ejcd = ejdvd = eject_cd = eject_cdrom = eject_disc = eject_disc_tray = \
eject_dvd = eject_tray = ejectcd = ejectcdrom =
ejectdisc = ejectdisctray = ejectdvd = ejecttray = ejtray = Command("eject
cdrom1")
I wouldn't actually do it like this (I'd probably start with a dict and add
to a class programmatically), but this is a simple display of how one can
use classes and other meta-constructs to make things look nicer. It also
doesn't deal with forcing the number of arguments to be correct, but this
is demo material and so I leave that to you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130725/6d660f5d/attachment.html>
More information about the Python-list
mailing list