Skip to content

Commit

Permalink
[#6] Hack to make it work on mac os
Browse files Browse the repository at this point in the history
The problem is that script behaves differently on mac os and also file.read does not return anything after it has read the file once. We have to add the seek to make sure that EOF is not cached. See http://docs.python.org/2/library/stdtypes.html#file.read.
  • Loading branch information
domoritz committed Jul 16, 2013
1 parent df6204a commit 4c0923c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions public/bin/shellshare
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import sys
import httplib2
import urllib
import os
import platform


def id_generator(size=9, chars=string.ascii_letters + string.digits):
Expand All @@ -22,9 +23,11 @@ def post(url, data):


def stream_file(path, url):
f = open(path, "r")
f = open(path, 'rb')
while True:
time.sleep(1)
# osx wants this because EOF is cached
f.seek(0, os.SEEK_CUR)
data = f.read()
if not (data == ""):
encoded_str = base64.b64encode(data)
Expand All @@ -35,7 +38,12 @@ tmp = tempfile.NamedTemporaryFile()
channel = sys.argv[1] if len(sys.argv) > 1 else id_generator()
url = 'http://www.shellshare.net/%s' % channel

if platform.system() == 'Darwin':
shell_args = '-qt 0'
else:
shell_args = '-qf'

print 'Sharing session in %s...' % url
thread.start_new_thread(stream_file, (tmp.name, url))
os.system('script -qf %s' % tmp.name)
os.system('script %s %s' % (shell_args, tmp.name))
print 'End of transmission.'

0 comments on commit 4c0923c

Please sign in to comment.