mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 11:48:13 +01:00
Read api url from config file
This commit is contained in:
34
bin/rec.py
34
bin/rec.py
@@ -17,6 +17,7 @@ import httplib, urllib
|
|||||||
import socket
|
import socket
|
||||||
import glob
|
import glob
|
||||||
import bz2
|
import bz2
|
||||||
|
import ConfigParser
|
||||||
|
|
||||||
SCRIPT_NAME = os.path.basename(sys.argv[0])
|
SCRIPT_NAME = os.path.basename(sys.argv[0])
|
||||||
|
|
||||||
@@ -25,7 +26,8 @@ class AsciiCast(object):
|
|||||||
BASE_DIR = os.path.expanduser("~/.ascii.io")
|
BASE_DIR = os.path.expanduser("~/.ascii.io")
|
||||||
QUEUE_DIR = BASE_DIR + "/queue"
|
QUEUE_DIR = BASE_DIR + "/queue"
|
||||||
|
|
||||||
def __init__(self, command, title, record_input):
|
def __init__(self, api_url, command, title, record_input):
|
||||||
|
self.api_url = api_url
|
||||||
self.path = AsciiCast.QUEUE_DIR + "/%i" % int(time.time())
|
self.path = AsciiCast.QUEUE_DIR + "/%i" % int(time.time())
|
||||||
self.command = command
|
self.command = command
|
||||||
self.title = title
|
self.title = title
|
||||||
@@ -80,7 +82,7 @@ class AsciiCast(object):
|
|||||||
return process.communicate()[0].strip()
|
return process.communicate()[0].strip()
|
||||||
|
|
||||||
def _upload(self):
|
def _upload(self):
|
||||||
url = Uploader(self.path).upload()
|
url = Uploader(self.api_url, self.path).upload()
|
||||||
if url:
|
if url:
|
||||||
print url
|
print url
|
||||||
return True
|
return True
|
||||||
@@ -256,9 +258,8 @@ class Uploader(object):
|
|||||||
Uploads recorded script to website using HTTP based API.
|
Uploads recorded script to website using HTTP based API.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
API_URL = os.environ.get('ASCII_IO_API_URL', 'http://ascii.io/api/asciicasts')
|
def __init__(self, api_url, path):
|
||||||
|
self.api_url = api_url
|
||||||
def __init__(self, path):
|
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
def upload(self):
|
def upload(self):
|
||||||
@@ -274,7 +275,7 @@ class Uploader(object):
|
|||||||
|
|
||||||
fields = ["-F asciicast[%s]=@%s/%s" % (f, self.path, files[f]) for f in files]
|
fields = ["-F asciicast[%s]=@%s/%s" % (f, self.path, files[f]) for f in files]
|
||||||
|
|
||||||
cmd = "curl -sS -o - %s %s" % (' '.join(fields), Uploader.API_URL)
|
cmd = "curl -sS -o - %s %s" % (' '.join(fields), '%s/asciicasts' % self.api_url)
|
||||||
|
|
||||||
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
|
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
@@ -354,8 +355,27 @@ def main():
|
|||||||
|
|
||||||
command = os.environ['SHELL'].split()
|
command = os.environ['SHELL'].split()
|
||||||
title = None
|
title = None
|
||||||
|
|
||||||
|
config = ConfigParser.RawConfigParser()
|
||||||
|
cfg_file = os.path.expanduser('~/.ascii.io/config')
|
||||||
|
try:
|
||||||
|
config.read(cfg_file)
|
||||||
|
except ConfigParser.ParsingError:
|
||||||
|
print('Config file %s contains syntax errors' % cfg_file)
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
try:
|
||||||
|
record_input = config.getboolean('record', 'input')
|
||||||
|
except ConfigParser.NoSectionError:
|
||||||
record_input = False
|
record_input = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
api_url = config.get('api', 'url')
|
||||||
|
except ConfigParser.NoSectionError:
|
||||||
|
api_url = 'http://ascii.io/api'
|
||||||
|
|
||||||
|
api_url = os.environ.get('ASCII_IO_API_URL', api_url)
|
||||||
|
|
||||||
for opt, arg in opts:
|
for opt, arg in opts:
|
||||||
if opt in ('-h', '--help'):
|
if opt in ('-h', '--help'):
|
||||||
usage()
|
usage()
|
||||||
@@ -372,7 +392,7 @@ def main():
|
|||||||
|
|
||||||
if action == 'rec':
|
if action == 'rec':
|
||||||
check_pending()
|
check_pending()
|
||||||
if not AsciiCast(command, title, record_input).create():
|
if not AsciiCast(api_url, command, title, record_input).create():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif action == 'upload':
|
elif action == 'upload':
|
||||||
upload_pending()
|
upload_pending()
|
||||||
|
|||||||
2
config.example
Normal file
2
config.example
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[api]
|
||||||
|
url = http://localhost:3000/api
|
||||||
Reference in New Issue
Block a user