#!/usr/bin/env python

import sys
import json
import urllib2
import shelx
import subprocess

class Plz(object):
  def __init__(self, arg):
    self.host = 'http://slackware.cs.utah.edu/pub/slackware'
    self.api  = 'http://slackware-packages.herokuapp.com/package'
    self.target_dir = '/boot/extra'

    self.arg      = arg
    self.command  = arg[1]
    self.name     = arg[2]
    self.version  = arg[3]

  def install(self):
    if not _installed():
      _download()
      _installpkg()

  def _installpkg(self):
    file = _path(self.target_dir, self.pkg['file_name'])
    subprocess.call(['installpkg', file])

  def _download(self):
    api = _path([self.api, self.name, self.version])
    self.pkg = _get(api)
    local_pkg  = _path([self.target_dir, self.pkg['file_name']])

    if not os.path.isfile(local_pkg):
      _wget(_path([self.host, self.pkg['path']]))

  def _installed(self):
    return self.pkg['package_name'] in _raw_installed_packages

  def _raw_installed_packages():
    return os.listdir('/var/log/packages/')

  def _wget(self, url):
    cmd = 'wget -Pq {0} {1}'.format(target_dir, url)
    subprocess.call(shlex.split(cmd))

  def _get(url):
    response = urllib2.urlopen(url)
    return json.load(response)

  def _path(list):
    return ('/').join(list)

# CLI
args = sys.argv
if len(args) == 4:
  plz = Plz(args)
  plz.install()
else:
  exit("Usage: plz install NAME VERSION")

@@ -16,16 +16,26 @@
 python%0A%0A
+import os%0A
 import s
@@ -73,18 +73,18 @@
 mport sh
-e
 l
+e
 x%0Aimport
@@ -191,26 +191,16 @@
 .edu/pub
-/slackware
 '%0A    se
@@ -257,16 +257,17 @@
 /package
+s
 '%0A    se
@@ -401,16 +401,39 @@
 = arg%5B3%5D
+%0A    self.pkg      = ''
 %0A%0A  def 
@@ -455,61 +455,120 @@
     
-if not _installed():%0A      _download()%0A      
+self._download()%0A    self._installpkg()%0A%0A%0A  # Private methods%0A%0A  def _installpkg(self):%0A    if not self.
 _install
 pkg(
@@ -567,40 +567,78 @@
 tall
-pkg()%0A%0A  def _installpkg(self):%0A
+ed():%0A      print %22Installing %7B0%7D%22.format(self.pkg%5B'package_name'%5D)%0A  
     
@@ -644,22 +644,28 @@
  file = 
+self.
 _path(
+%5B
 self.tar
@@ -690,26 +690,29 @@
 'file_name'%5D
+%5D
 )%0A
+  
     subproce
@@ -775,16 +775,21 @@
   api = 
+self.
 _path(%5Bs
@@ -806,17 +806,106 @@
 elf.name
-,
+%5D)%0A    pkg = self._get(api)%0A%0A    versions = %5Bv for v in pkg%5B'versions'%5D if v%5B'version'%5D ==
  self.ve
@@ -910,17 +910,16 @@
 version%5D
-)
 %0A    sel
@@ -926,25 +926,29 @@
 f.pkg = 
-_get(api)
+versions%5B-1%5D%0A
 %0A    loc
@@ -957,16 +957,21 @@
 _pkg  = 
+self.
 _path(%5Bs
@@ -1055,22 +1055,95 @@
 :%0A      
+print %22Downloading %7B0%7D%22.format(self.pkg%5B'package_name'%5D)%0A      self.
 _wget(
+self.
 _path(%5Bs
@@ -1236,16 +1236,21 @@
 me'%5D in 
+self.
 _raw_ins
@@ -1264,16 +1264,18 @@
 packages
+()
 %0A%0A  def 
@@ -1298,16 +1298,20 @@
 ackages(
+self
 ):%0A    r
@@ -1395,10 +1395,10 @@
 et -
-P
 q
+P
  %7B0%7D
@@ -1410,16 +1410,21 @@
 .format(
+self.
 target_d
@@ -1482,16 +1482,22 @@
 ef _get(
+self, 
 url):%0A  
@@ -1574,16 +1574,22 @@
 f _path(
+self, 
 list):%0A 

Add plz.py