<div dir="ltr">On 25 July 2013 14:24, Devyn Collier Johnson <span dir="ltr"><<a href="mailto:devyncjohnson@gmail.com" target="_blank">devyncjohnson@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Aloha Python Users!<br>
<br>
   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<br>


<br>
import boash; <a href="http://boash.ls" target="_blank">boash.ls</a>()<br>
<br>
   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.<br>
<br>
   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.<br>

</blockquote><div><br></div><div>1) Have you tested everything? At first glance some of those look like they won't work.</div><div><br></div><div>2) Whenever you repeat yourself, *especially* at this magnitude, you're doing something seriously wrong - *especially* in Python.</div>

<div><br></div><div>*Completely-untestedly-and-super-quick-hackedly:*</div><div><div><br></div><div>import re, sys, subprocess, platform</div><div>class Command:<br></div><div><span class="" style="white-space:pre">     </span>def __init__(self, command=None):</div>

<div><span class="" style="white-space:pre">            </span>self.command = command</div><div><span class="" style="white-space:pre">     </span>def __call__(self, *args):<br></div><div><span class="" style="white-space:pre">               </span>command_list = [self.command] if self.command else []</div>

<div><span class="" style="white-space:pre">            </span>command_list.extend(args)</div><div><span class="" style="white-space:pre">          </span>print(subprocess.getoutput([command_list]))<br></div><div>def uname():<br></div><div>

<span class="" style="white-space:pre">       </span>print(platform.uname())</div><div>def lsof():<br></div><div><span class="" style="white-space:pre">        </span>print(subprocess.getoutput(lsof))</div><div>apropos   = Command("apropos")<br>

</div><div>arora     = Command("(arora &)")</div><div>dir       = Command("dir")</div><div>dolphin   = Command("(dolphin &)")</div><div>env       = Command("env")</div><div>

finger    = Command("finger")</div><div>firefox   = Command("(firefox &)")</div><div>free      = Command("free")</div><div>geany     = Command("(geany &)")</div><div>getcwd    = Command("pwd")</div>

<div>go_back   = Command("cd !!:1")</div><div>halt      = Command("shutdown -h now")</div><div>hostname  = Command("hostname")</div><div>konqueror = Command("(konqueror &)")</div>

<div>ls        = Command("ls")</div><div>lsof      = Command("lsof")</div><div>man       = Command("man")</div><div>mplayer   = Command("(mplayer &)")</div><div>nautilus  = Command("(nautilus &)")</div>

<div>nvlc      = Command("(nvlc &)")</div><div>opera     = Command("(opera &)")</div><div>pwd       = Command("pwd")</div><div>qvlc      = Command("(qvlc &)")</div><div>

repeat    = Command("!")</div><div>runlevel  = Command("runlevel")</div><div>rvlc      = Command("(rvlc &)")</div><div>smplayer  = Command("(smplayer &)")</div><div>svlc      = Command("(svlc &)")</div>

<div>vlc       = Command("(vlc &)")</div><div>whoami    = Command("whoami")</div><div>xterm     = Command("(xterm &)")</div><div>arch = architecture = Command("arch")<br></div>

<div>bash = cmd = command = shell = Command()<br></div><div>last_cmd = last_command = repeat_cmd = Command("!!")<br></div><div>ll = vdir = Command("ls - l")<br></div><div>no_login = no_logins = nologin = nologins = Command("shutdown -k now")<br>

</div><div>power_down = power_off = powerdown = poweroff = Command("shutdown -P now")<br></div><div>reboot = restart = Command("shutdown -r now")<br></div><div>shut_down = shutdown = Command("shutdown now")<br>

</div><div>clear_bash_hist = clear_bash_history = clear_hist = clear_history = \<br></div><div><span class="" style="white-space:pre">  </span>del_bash_hist = del_hist = delete_bash_hist = delete_bash_history = \</div><div>

<span class="" style="white-space:pre">       </span>delete_hist = delete_history = Command("history -c")</div><div>ejcd = ejdvd = eject_cd = eject_cdrom = eject_disc = eject_disc_tray = \<br></div><div><span class="" style="white-space:pre">    </span>eject_dvd = eject_tray = ejectcd = ejectcdrom =</div>

<div><span class="" style="white-space:pre">    </span>ejectdisc = ejectdisctray = ejectdvd = ejecttray = ejtray = Command("eject cdrom1")</div></div><div><br></div><div><br></div><div><br></div><div>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.</div>

</div></div></div>