mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 11:48:13 +01:00
Generate user token and assign it to recorded asciicast
This commit is contained in:
24
bin/rec.py
24
bin/rec.py
@@ -18,6 +18,7 @@ import socket
|
|||||||
import glob
|
import glob
|
||||||
import bz2
|
import bz2
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
|
import uuid
|
||||||
|
|
||||||
SCRIPT_NAME = os.path.basename(sys.argv[0])
|
SCRIPT_NAME = os.path.basename(sys.argv[0])
|
||||||
|
|
||||||
@@ -26,8 +27,9 @@ 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, api_url, command, title, record_input):
|
def __init__(self, api_url, user_token, command, title, record_input):
|
||||||
self.api_url = api_url
|
self.api_url = api_url
|
||||||
|
self.user_token = user_token
|
||||||
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
|
||||||
@@ -61,6 +63,7 @@ class AsciiCast(object):
|
|||||||
columns = int(self._get_cmd_output(['tput', 'cols']))
|
columns = int(self._get_cmd_output(['tput', 'cols']))
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
|
'user_token' : self.user_token,
|
||||||
'duration' : self.duration,
|
'duration' : self.duration,
|
||||||
'recorded_at': recorded_at,
|
'recorded_at': recorded_at,
|
||||||
'title' : self.title,
|
'title' : self.title,
|
||||||
@@ -355,6 +358,10 @@ def main():
|
|||||||
action = args[0]
|
action = args[0]
|
||||||
|
|
||||||
config = ConfigParser.RawConfigParser()
|
config = ConfigParser.RawConfigParser()
|
||||||
|
config.add_section('user')
|
||||||
|
config.add_section('api')
|
||||||
|
config.add_section('record')
|
||||||
|
|
||||||
cfg_file = os.path.expanduser('~/.ascii.io/config')
|
cfg_file = os.path.expanduser('~/.ascii.io/config')
|
||||||
try:
|
try:
|
||||||
config.read(cfg_file)
|
config.read(cfg_file)
|
||||||
@@ -362,16 +369,25 @@ def main():
|
|||||||
print('Config file %s contains syntax errors' % cfg_file)
|
print('Config file %s contains syntax errors' % cfg_file)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
try:
|
||||||
|
user_token = config.get('user', 'token')
|
||||||
|
except ConfigParser.NoOptionError:
|
||||||
|
user_token = str(uuid.uuid1())
|
||||||
|
config.set('user', 'token', user_token)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
record_input = config.getboolean('record', 'input')
|
record_input = config.getboolean('record', 'input')
|
||||||
except ConfigParser.NoSectionError:
|
except ConfigParser.NoOptionError:
|
||||||
record_input = False
|
record_input = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
api_url = config.get('api', 'url')
|
api_url = config.get('api', 'url')
|
||||||
except ConfigParser.NoSectionError:
|
except ConfigParser.NoOptionError:
|
||||||
api_url = 'http://ascii.io/api'
|
api_url = 'http://ascii.io/api'
|
||||||
|
|
||||||
|
with open(cfg_file, 'wb') as configfile:
|
||||||
|
config.write(configfile)
|
||||||
|
|
||||||
api_url = os.environ.get('ASCII_IO_API_URL', api_url)
|
api_url = os.environ.get('ASCII_IO_API_URL', api_url)
|
||||||
|
|
||||||
command = None
|
command = None
|
||||||
@@ -393,7 +409,7 @@ def main():
|
|||||||
|
|
||||||
if action == 'rec':
|
if action == 'rec':
|
||||||
check_pending()
|
check_pending()
|
||||||
if not AsciiCast(api_url, command, title, record_input).create():
|
if not AsciiCast(api_url, user_token, command, title, record_input).create():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif action == 'upload':
|
elif action == 'upload':
|
||||||
upload_pending()
|
upload_pending()
|
||||||
|
|||||||
Reference in New Issue
Block a user