Skip to content

Commit

Permalink
add status updater
Browse files Browse the repository at this point in the history
  • Loading branch information
jrising committed Aug 21, 2016
1 parent 6237b43 commit 0cb8c9b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
46 changes: 44 additions & 2 deletions local/loco.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys, os, cmd, csv, urllib, subprocess, psutil
import sys, os, cmd, csv, urllib, subprocess, psutil, random, string
from sandbox import Sandbox
import status

if sys.platform in ['linux', 'linux2']:
import x_server
Expand All @@ -11,6 +12,15 @@
import gui_server
local_server = gui_server.GUILocalServer()

try:
import keyring
except:
print "keyring not available: passwd will not save."

## Record this instance
status_id = status.register(status.getip(), 'loco')
print "Status ID: " + status_id

dictionary = {}
commands = {}
reminders = {}
Expand Down Expand Up @@ -70,6 +80,18 @@ def do_cd(self, path):
os.chdir(path)
self.reset_prompt()

def complete_cd(self, text, line, begidx, endidx):
results = []
fulldir, partfile = os.path.split(line.split()[1])
for filename in os.listdir(os.path.join(os.getcwd(), fulldir)):
if filename[:len(partfile)] == partfile:
if os.path.isdir(filename):
results.append(filename + '/')
else:
results.append(filename)

return results

def do_pr(self, pid):
"""Start tracking a process by PID"""
if pid == '':
Expand Down Expand Up @@ -119,7 +141,7 @@ def do_term(self, command):
if command in dictionary:
command = "cd " + dictionary[command]

local_server.open_terminal(command)
local_server.open_terminal("cd " + os.getcwd() + "; " + command)

def do_ssh(self, where):
"""Ssh to a known location."""
Expand All @@ -128,6 +150,26 @@ def do_ssh(self, where):
else:
print "Unrecognized: ssh: " + where

def do_passwd(self, line):
parts = line.split()
system = parts[0]
username = parts[1]

try:
# Is there already a password for this?
password = keyring.get_password(system, username)
if password:
print password
return
except:
pass

length = 13
chars = string.ascii_letters + string.digits + '!@#$%^&*()'
password = ''.join(random.choice(chars) for i in range(length))
keyring.set_password(system, username, password)
print password

def do_open(self, thing):
"""Open an application or a file, as with the Finder."""
local_server.open_thing(thing)
Expand Down
3 changes: 1 addition & 2 deletions local/macos_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ def open_url(self, url):
tell application "Google Chrome"
open location "%s"
end tell
EOD""" % (url)

EOD""" % (url))
26 changes: 26 additions & 0 deletions local/status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import urllib, urllib2, re

def doit(op, **kw):
kw['op'] = op
kw['pass'] = 'qhww0c'
data = urllib.urlencode(kw)
req = urllib2.Request("http://console.existencia.org/ss/status.php", data)
response = urllib2.urlopen(req)
return response.read()

def getip():
response = urllib2.urlopen('http://checkip.dyndns.com/')
data = str(response.read())
return re.compile(r'Address: (\d+\.\d+\.\d+\.\d+)').search(data).group(1)

def register(server, name):
return doit('register', server=server, name=name)

def update(id, msgtype, message):
return doit('update', id=id, msgtype=msgtype, message=message)

def complete(id):
return update(id, 'done', 'done')

def notify(id, msgtype, message):
return doit('notify', id=id, msgtype=msgtype, message=message)

0 comments on commit 0cb8c9b

Please sign in to comment.