<div dir="ltr"><div class="gmail_extra"><div style="color:rgb(0,0,0)" class="gmail_default">You've gotten plenty of good advice from people discussing the coding and coding style itself, I'll provide some feedback from the vantage point of a perspective user.</div>
<br><br><div class="gmail_quote">On Thu, Jul 25, 2013 at 9:24 AM, Devyn Collier Johnson <span dir="ltr"><<a href="mailto:devyncjohnson@gmail.com" target="_blank">devyncjohnson@gmail.com</a>></span> wrote:<br><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></blockquote><div><br></div><div style="color:rgb(0,0,0)" class="gmail_default">I actually wrote a program recently in which I wanted access to unix "ls" command, and I wanted it to behave as close to the real, UNIX "ls" as possible.</div>
<div style="color:rgb(0,0,0)" class="gmail_default"><br></div><div style="color:rgb(0,0,0)" class="gmail_default">This would seem like a perfect use-case for your module, but the problem is that the 'ls' command in your module does not behave much like the real 'ls' command.  You never let any of the 'system' commands in your module access any arguments.  More often than not, I use "ls" with several command-line arguments, like:</div>
<div style="color:rgb(0,0,0)" class="gmail_default"><br></div><div style="color:rgb(0,0,0)" class="gmail_default">ls --color=auto -lthr dir_basename*/</div><div style="color:rgb(0,0,0)" class="gmail_default"><br></div><div style="color:rgb(0,0,0)" class="gmail_default">
Even if you're just spawning 'ls' directly, this is actually non-trivial to implement.  You need globbing on all non-option arguments, you may want to pass up the return code somehow, depending on what the user wants to do:</div>
<div style="color:rgb(0,0,0)" class="gmail_default"><br></div><div class="gmail_default"><div class="gmail_default"><font color="#000000">[bash ]$ ls nodir</font></div><div class="gmail_default"><font color="#000000">ls: nodir: No such file or directory</font></div>
<div class="gmail_default"><font color="#000000">[bash ]$ echo $?</font></div><div class="gmail_default"><font color="#000000">1</font></div><div class="gmail_default"><font color="#000000"><br></font></div><div class="gmail_default" style>
<font color="#000000">Also, 'ls' in the terminal behaves like "ls -C" when called from your module.  In the framework of my program, my 'ls' command looks like this:</font></div><div class="gmail_default" style>
<font color="#000000"><br></font></div><div class="gmail_default" style><font color="#000000"><div class="gmail_default">class ls(Action):</div><div class="gmail_default">   """</div><div class="gmail_default">
   Lists directory contents. Like UNIX 'ls'</div><div class="gmail_default">   """</div><div class="gmail_default">   needs_parm = False</div><div class="gmail_default">   def init(self, arg_list):</div>
<div class="gmail_default">      from glob import glob</div><div class="gmail_default">      self.args = []</div><div class="gmail_default">      # Process the argument list to mimic the real ls as much as possible</div><div class="gmail_default">
      while True:</div><div class="gmail_default">         try:</div><div class="gmail_default">            arg = arg_list.get_next_string()</div><div class="gmail_default">            if not arg.startswith('-'):</div>
<div class="gmail_default">               # Glob this argument</div><div class="gmail_default">               globarg = glob(arg)</div><div class="gmail_default">               if len(globarg) > 0:</div><div class="gmail_default">
                  self.args.extend(globarg)</div><div class="gmail_default">               else:</div><div class="gmail_default">                  self.args.append(arg)</div><div class="gmail_default">            else:</div>
<div class="gmail_default">               self.args.append(arg)</div><div class="gmail_default">         except NoArgument:</div><div class="gmail_default">            break</div><div class="gmail_default"><br></div><div class="gmail_default">
   def __str__(self):</div><div class="gmail_default">      from subprocess import Popen, PIPE</div><div class="gmail_default">      process = Popen(['/bin/ls', '-C'] + self.args, stdout=PIPE, stderr=PIPE)</div>
<div class="gmail_default">      out, err = process.communicate('')</div><div class="gmail_default">      process.wait()</div><div class="gmail_default">      return out + err</div><div><br></div><div style>[I have omitted the Action base class, which processes the user command-line arguments and passes it to the init() method in arg_list -- this listing was just to give you a basic idea of the complexity of getting a true-er 'ls' command].</div>
<div style><br></div><div style>Your 'uname' command is likewise limited (and the printout looks strange:</div><div style><br></div><div style><div>>>> print(platform.uname())</div><div>('Linux', 'Batman', '3.3.8-gentoo', '#1 SMP Fri Oct 5 14:14:57 EDT 2012', 'x86_64', 'AMD FX(tm)-6100 Six-Core Processor')</div>
<div><br></div><div style>Whereas:</div><div style><br></div><div style>[bash $] uname -a</div><div style><div>Linux Batman 3.3.8-gentoo #1 SMP Fri Oct 5 14:14:57 EDT 2012 x86_64 AMD FX(tm)-6100 Six-Core Processor AuthenticAMD GNU/Linux</div>
<div><br></div><div style>You may want to change that to:</div><div style><br></div><div style>def uname():</div><div style>    print(' '.join(platform.uname()))</div><div style><br></div><div style>Although again, oftentimes people want only something specific from uname (like -m or -n).</div>
<div style><br></div><div style>HTH,</div><div style>Jason</div><div style><br></div></div></div></font></div></div></div>
</div></div>