├── tests ├── __init__.py ├── integration.sh ├── stdout_test.py ├── test_helper.py ├── pty_recorder_test.py └── config_test.py ├── asciinema ├── commands │ ├── __init__.py │ ├── command.py │ ├── auth.py │ ├── play.py │ ├── upload.py │ └── record.py ├── http_adapter.py ├── __init__.py ├── player.py ├── recorder.py ├── stdout.py ├── api.py ├── config.py ├── urllib_http_adapter.py ├── asciicast.py ├── pty_recorder.py └── __main__.py ├── setup.cfg ├── .gitignore ├── .travis.yml ├── Vagrantfile ├── Makefile ├── setup.py ├── install ├── doc └── asciicast-v1.md ├── CONTRIBUTING.md ├── CHANGELOG.md ├── man └── asciinema.1 ├── README.md └── LICENSE /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /asciinema/commands/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.md 3 | -------------------------------------------------------------------------------- /asciinema/http_adapter.py: -------------------------------------------------------------------------------- 1 | class HTTPConnectionError(Exception): 2 | pass 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /dist 2 | tmp 3 | *.pyc 4 | *.tar.gz 5 | *.tar.bz2 6 | *.tar.xz 7 | *.zip 8 | *.egg-info 9 | /build 10 | -------------------------------------------------------------------------------- /asciinema/__init__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | __author__ = 'Marcin Kulik' 4 | __version__ = '1.3.0' 5 | 6 | if sys.version_info[0] < 3: 7 | raise ImportError('Python < 3 is unsupported.') 8 | -------------------------------------------------------------------------------- /asciinema/player.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import time 3 | 4 | 5 | class Player: 6 | 7 | def play(self, asciicast, max_wait=None, speed=1.0): 8 | for delay, text in asciicast.stdout: 9 | if max_wait and delay > max_wait: 10 | delay = max_wait 11 | time.sleep(delay / speed) 12 | sys.stdout.write(text) 13 | sys.stdout.flush() 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: python 3 | 4 | python: 5 | - "3.2" 6 | - "3.3" 7 | - "3.4" 8 | - "3.5" 9 | 10 | before_install: 11 | - pip install pep8 12 | 13 | script: 14 | - find . -name \*.py -exec pep8 --ignore=E501 {} + 15 | - make test 16 | 17 | notifications: 18 | irc: 19 | channels: 20 | - "chat.freenode.net#asciinema" 21 | use_notice: true 22 | skip_join: true 23 | -------------------------------------------------------------------------------- /asciinema/commands/command.py: -------------------------------------------------------------------------------- 1 | class Command: 2 | 3 | def __init__(self, quiet=False): 4 | self.quiet = quiet 5 | 6 | def print(self, text): 7 | if not self.quiet: 8 | print(text) 9 | 10 | def print_info(self, text): 11 | if not self.quiet: 12 | print("\x1b[32m~ %s\x1b[0m" % text) 13 | 14 | def print_warning(self, text): 15 | if not self.quiet: 16 | print("\x1b[33m~ %s\x1b[0m" % text) 17 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! 5 | VAGRANTFILE_API_VERSION = "2" 6 | 7 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 8 | 9 | config.vm.provider :virtualbox do |vb| 10 | vb.customize ["modifyvm", :id, "--memory", "1024"] 11 | end 12 | 13 | config.vm.define "archlinux" do |c| 14 | c.vm.box = "terrywang/archlinux" 15 | end 16 | 17 | config.vm.define "ubuntu" do |c| 18 | c.vm.box = "ubuntu/trusty64" 19 | end 20 | 21 | end 22 | -------------------------------------------------------------------------------- /asciinema/commands/auth.py: -------------------------------------------------------------------------------- 1 | from asciinema.commands.command import Command 2 | 3 | 4 | class AuthCommand(Command): 5 | 6 | def __init__(self, api_url, api_token): 7 | Command.__init__(self) 8 | self.api_url = api_url 9 | self.api_token = api_token 10 | 11 | def execute(self): 12 | url = '%s/connect/%s' % (self.api_url, self.api_token) 13 | self.print('Open the following URL in a browser to register your API ' 14 | 'token and assign any recorded asciicasts to your profile:\n' 15 | '%s' % url) 16 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | NAME=asciinema 2 | VERSION=`python3 -c "import asciinema; print(asciinema.__version__)"` 3 | 4 | test: test-unit test-integration 5 | 6 | test-unit: 7 | nosetests 8 | 9 | test-integration: 10 | tests/integration.sh 11 | 12 | release: test tag push 13 | 14 | release-test: test push-test 15 | 16 | tag: 17 | git tag | grep "v$(VERSION)" && echo "Tag v$(VERSION) exists" && exit 1 || true 18 | git tag -s -m "Releasing $(VERSION)" v$(VERSION) 19 | git push --tags 20 | 21 | push: 22 | python3 setup.py sdist upload -r pypi 23 | 24 | push-test: 25 | python3 setup.py sdist upload -r pypitest 26 | 27 | release: test tag push 28 | 29 | .PHONY: test test-unit test-integration release release-test tag push push-test 30 | -------------------------------------------------------------------------------- /asciinema/commands/play.py: -------------------------------------------------------------------------------- 1 | from asciinema.commands.command import Command 2 | from asciinema.player import Player 3 | import asciinema.asciicast as asciicast 4 | 5 | 6 | class PlayCommand(Command): 7 | 8 | def __init__(self, filename, max_wait, speed, player=None): 9 | Command.__init__(self) 10 | self.filename = filename 11 | self.max_wait = max_wait 12 | self.speed = speed 13 | self.player = player if player is not None else Player() 14 | 15 | def execute(self): 16 | try: 17 | self.player.play(asciicast.load(self.filename), self.max_wait, self.speed) 18 | 19 | except asciicast.LoadError as e: 20 | self.print_warning("Playback failed: %s" % str(e)) 21 | return 1 22 | except KeyboardInterrupt: 23 | return 1 24 | 25 | return 0 26 | -------------------------------------------------------------------------------- /asciinema/commands/upload.py: -------------------------------------------------------------------------------- 1 | from asciinema.commands.command import Command 2 | from asciinema.api import APIError 3 | 4 | 5 | class UploadCommand(Command): 6 | 7 | def __init__(self, api, filename): 8 | Command.__init__(self) 9 | self.api = api 10 | self.filename = filename 11 | 12 | def execute(self): 13 | try: 14 | url, warn = self.api.upload_asciicast(self.filename) 15 | 16 | if warn: 17 | self.print_warning(warn) 18 | 19 | self.print(url) 20 | 21 | except FileNotFoundError as e: 22 | self.print_warning("Upload failed: %s" % str(e)) 23 | return 1 24 | 25 | except APIError as e: 26 | self.print_warning("Upload failed: %s" % str(e)) 27 | self.print_warning("Retry later by running: asciinema upload %s" % self.filename) 28 | return 1 29 | 30 | return 0 31 | -------------------------------------------------------------------------------- /tests/integration.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | export ASCIINEMA_CONFIG_HOME=`mktemp -d 2>/dev/null || mktemp -d -t asciinema-config-home` 7 | TMP_DATA_DIR=`mktemp -d 2>/dev/null || mktemp -d -t asciinema-data-dir` 8 | trap "echo rm -rf $ASCIINEMA_CONFIG_HOME $TMP_DATA_DIR" EXIT 9 | 10 | function asciinema() { 11 | python3 -m asciinema "$@" 12 | } 13 | 14 | asciinema -h 15 | 16 | asciinema --version 17 | 18 | asciinema auth 19 | 20 | asciinema rec -c who "$TMP_DATA_DIR/1.json" 21 | 22 | bash -c "sleep 1; pkill -28 -n -f 'm asciinema'" & 23 | asciinema rec -c 'bash -c "echo t3st; sleep 2; echo ok"' "$TMP_DATA_DIR/2.json" 24 | 25 | bash -c "sleep 1; pkill -n -f 'bash -c echo t3st'" & 26 | asciinema rec -c 'bash -c "echo t3st; sleep 2; echo ok"' "$TMP_DATA_DIR/3.json" 27 | 28 | bash -c "sleep 1; pkill -9 -n -f 'bash -c echo t3st'" & 29 | asciinema rec -c 'bash -c "echo t3st; sleep 2; echo ok"' "$TMP_DATA_DIR/4.json" 30 | -------------------------------------------------------------------------------- /tests/stdout_test.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | from nose.tools import assert_equal 4 | from .test_helper import Test, FakeClock 5 | from asciinema.stdout import Stdout 6 | 7 | 8 | class TestStdout(Test): 9 | 10 | def setUp(self): 11 | Test.setUp(self) 12 | self.real_time = time.time 13 | time.time = FakeClock([1, 3, 10, 13, 17]).time 14 | 15 | def tearDown(self): 16 | time.time = self.real_time 17 | 18 | def test_write(self): 19 | stdout = Stdout() 20 | 21 | stdout.write(b'foo') 22 | stdout.write(b'barbaz') 23 | stdout.write('żó'.encode('utf-8') + bytes([0xc5])) 24 | stdout.write(bytes([0x82]) + 'ć'.encode('utf-8')) 25 | 26 | assert_equal([[2, 'foo'], [7, 'barbaz'], [3, 'żó'], [4, 'łć']], stdout.frames) 27 | 28 | def test_close(self): 29 | stdout = Stdout() 30 | 31 | stdout.write(b'foo') 32 | stdout.write(b'barbaz') 33 | stdout.close() 34 | 35 | assert_equal(12, stdout.duration) 36 | -------------------------------------------------------------------------------- /asciinema/recorder.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | 4 | from .asciicast import Asciicast 5 | from .pty_recorder import PtyRecorder 6 | from .stdout import Stdout 7 | 8 | 9 | class Recorder: 10 | 11 | def __init__(self, pty_recorder=None, env=None): 12 | self.pty_recorder = pty_recorder if pty_recorder is not None else PtyRecorder() 13 | self.env = env if env is not None else os.environ 14 | 15 | def record(self, path, user_command, title, max_wait): 16 | command = user_command or self.env.get('SHELL') or 'sh' 17 | stdout = Stdout(max_wait) 18 | env = os.environ.copy() 19 | env['ASCIINEMA_REC'] = '1' 20 | 21 | self.pty_recorder.record_command(['sh', '-c', command], stdout, env) 22 | 23 | width = int(subprocess.check_output(['tput', 'cols'])) 24 | height = int(subprocess.check_output(['tput', 'lines'])) 25 | 26 | asciicast = Asciicast( 27 | stdout, 28 | width, 29 | height, 30 | stdout.duration, 31 | command=user_command, 32 | title=title, 33 | term=self.env.get('TERM'), 34 | shell=self.env.get('SHELL') 35 | ) 36 | 37 | asciicast.save(path) 38 | -------------------------------------------------------------------------------- /tests/test_helper.py: -------------------------------------------------------------------------------- 1 | import sys 2 | try: 3 | from StringIO import StringIO 4 | except ImportError: 5 | from io import StringIO 6 | 7 | 8 | stdout = None 9 | 10 | 11 | def assert_printed(expected): 12 | success = expected in stdout.getvalue() 13 | assert success, 'expected text "%s" not printed' % expected 14 | 15 | 16 | def assert_not_printed(expected): 17 | success = expected not in stdout.getvalue() 18 | assert success, 'not expected text "%s" printed' % expected 19 | 20 | 21 | class Test: 22 | 23 | def setUp(self): 24 | global stdout 25 | self.real_stdout = sys.stdout 26 | sys.stdout = stdout = StringIO() 27 | 28 | def tearDown(self): 29 | sys.stdout = self.real_stdout 30 | 31 | 32 | class FakeClock: 33 | 34 | def __init__(self, values): 35 | self.values = values 36 | self.n = 0 37 | 38 | def time(self): 39 | value = self.values[self.n] 40 | self.n += 1 41 | 42 | return value 43 | 44 | 45 | class FakeAsciicast: 46 | 47 | def __init__(self, cmd=None, title=None, stdout=None, meta_data=None): 48 | self.cmd = cmd 49 | self.title = title 50 | self.stdout = stdout 51 | self.meta_data = meta_data or {} 52 | -------------------------------------------------------------------------------- /tests/pty_recorder_test.py: -------------------------------------------------------------------------------- 1 | import os 2 | import pty 3 | 4 | from nose.tools import assert_equal 5 | from .test_helper import Test 6 | 7 | from asciinema.stdout import Stdout 8 | from asciinema.pty_recorder import PtyRecorder 9 | 10 | 11 | class FakeStdout: 12 | 13 | def __init__(self): 14 | self.data = [] 15 | self.closed = False 16 | 17 | def write(self, data): 18 | self.data.append(data) 19 | 20 | def close(self): 21 | self.close = True 22 | 23 | 24 | class TestPtyRecorder(Test): 25 | 26 | def setUp(self): 27 | self.real_os_write = os.write 28 | os.write = self.os_write 29 | 30 | def tearDown(self): 31 | os.write = self.real_os_write 32 | 33 | def os_write(self, fd, data): 34 | if fd != pty.STDOUT_FILENO: 35 | self.real_os_write(fd, data) 36 | 37 | def test_record_command_writes_to_stdout(self): 38 | pty_recorder = PtyRecorder() 39 | output = FakeStdout() 40 | 41 | command = ['python3', '-c', "import sys; import time; sys.stdout.write(\'foo\'); sys.stdout.flush(); time.sleep(0.01); sys.stdout.write(\'bar\')"] 42 | pty_recorder.record_command(command, output) 43 | 44 | assert_equal([b'foo', b'bar'], output.data) 45 | -------------------------------------------------------------------------------- /asciinema/stdout.py: -------------------------------------------------------------------------------- 1 | import time 2 | import codecs 3 | 4 | 5 | class Stdout: 6 | 7 | def __init__(self, max_wait=None): 8 | self.frames = [] 9 | self.max_wait = max_wait 10 | self.last_write_time = time.time() 11 | self.duration = 0 12 | self.decoder = codecs.getincrementaldecoder('UTF-8')('replace') 13 | 14 | def write(self, data): 15 | text = self.decoder.decode(data) 16 | if text: 17 | delay = self._increment_elapsed_time() 18 | self.frames.append([delay, text]) 19 | 20 | return len(data) 21 | 22 | def close(self): 23 | self._increment_elapsed_time() 24 | 25 | if len(self.frames) > 0: 26 | last_frame = self.frames[-1] 27 | if last_frame[1] == "exit\r\n" or last_frame[1] == "logout\r\n": 28 | self.frames = self.frames[0:-1] 29 | self.duration -= last_frame[0] 30 | 31 | def _increment_elapsed_time(self): 32 | # delay = int(delay * 1000000) / 1000000.0 # millisecond precission 33 | now = time.time() 34 | delay = now - self.last_write_time 35 | 36 | if self.max_wait and delay > self.max_wait: 37 | delay = self.max_wait 38 | 39 | self.duration += delay 40 | self.last_write_time = now 41 | 42 | return delay 43 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import asciinema 2 | import sys 3 | from setuptools import setup 4 | 5 | if sys.version_info[0] < 3: 6 | sys.exit('Python < 3 is unsupported.') 7 | 8 | url_template = 'https://github.com/asciinema/asciinema/archive/v%s.tar.gz' 9 | requirements = [] 10 | 11 | setup( 12 | name='asciinema', 13 | version=asciinema.__version__, 14 | packages=['asciinema', 'asciinema.commands'], 15 | license='GNU GPLv3', 16 | description='Terminal session recorder', 17 | author=asciinema.__author__, 18 | author_email='m@ku1ik.com', 19 | url='https://asciinema.org', 20 | download_url=(url_template % asciinema.__version__), 21 | entry_points={ 22 | 'console_scripts': [ 23 | 'asciinema = asciinema.__main__:main', 24 | ], 25 | }, 26 | install_requires=requirements, 27 | classifiers=[ 28 | 'Development Status :: 5 - Production/Stable', 29 | 'Environment :: Console', 30 | 'Intended Audience :: Developers', 31 | 'Intended Audience :: System Administrators', 32 | 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', 33 | 'Natural Language :: English', 34 | 'Programming Language :: Python', 35 | 'Programming Language :: Python :: 3', 36 | 'Programming Language :: Python :: 3.2', 37 | 'Programming Language :: Python :: 3.3', 38 | 'Programming Language :: Python :: 3.4', 39 | 'Programming Language :: Python :: 3.5', 40 | 'Topic :: System :: Shells', 41 | 'Topic :: Terminals', 42 | 'Topic :: Utilities' 43 | ], 44 | ) 45 | -------------------------------------------------------------------------------- /install: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script installs asciinema cli on your system by downloading a binary 4 | # compatible with your platform and putting it in your $PATH. 5 | 6 | { # Prevent execution if this script was only partially downloaded 7 | 8 | set -e 9 | 10 | case "$(uname -s).$(uname -m)" in 11 | Linux.x86_64) platform=linux-amd64;; 12 | Linux.i?86) platform=linux-386;; 13 | Linux.armv6l) platform=linux-arm;; 14 | Linux.armv7l) platform=linux-arm;; 15 | FreeBSD.amd64) platform=freebsd-amd64;; 16 | FreeBSD.i386) platform=freebsd-386;; 17 | Darwin.x86_64) platform=darwin-amd64;; 18 | Darwin.i?86) platform=darwin-386;; 19 | *) echo "Sorry, there is no asciinema binary available for your platform. Try building from source." >&2; exit 1;; 20 | esac 21 | 22 | version=1.2.0 23 | url="https://github.com/asciinema/asciinema/releases/download/v${version}/asciinema-${version}-${platform}.tar.gz" 24 | bin_name="asciinema" 25 | sudo="" 26 | 27 | tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'asciinema-tmp') 28 | trap 'rm -rf $tmpdir' EXIT 29 | 30 | echo "Downloading asciinema v${version} for $platform..." 31 | curl -L --progress-bar "$url" | tar xz -C $tmpdir 32 | 33 | if [ -d "$HOME/bin" ]; then 34 | if echo ":$PATH:" | grep -q ":~/bin:" || echo ":$PATH:" | grep -q ":$HOME/bin:"; then 35 | target="$HOME/bin/$bin_name" 36 | fi 37 | elif [ -d "/usr/local/bin" ]; then 38 | if echo ":$PATH:" | grep -q ":/usr/local/bin:"; then 39 | target="/usr/local/bin/$bin_name" 40 | if [ ! -w /usr/local/bin ]; then 41 | sudo=sudo 42 | echo "Warning: you may be asked for administrator password to save the file in /usr/local/bin directory" 43 | fi 44 | fi 45 | fi 46 | 47 | if [ -z "$target" ]; then 48 | target="$PWD/$bin_name" 49 | echo "Warning: couldn't find ~/bin or /usr/local/bin in your \$PATH" 50 | fi 51 | 52 | echo "Installing to $target..." 53 | if $sudo cp $tmpdir/asciinema*/asciinema $target; then 54 | $sudo chmod a+x $target 55 | echo "Success." 56 | echo 57 | echo "Start recording your terminal by running: asciinema rec" 58 | else 59 | echo "Error: couldn't copy $bin_name to $target" 60 | fi 61 | 62 | } # End of wrapping 63 | -------------------------------------------------------------------------------- /doc/asciicast-v1.md: -------------------------------------------------------------------------------- 1 | # asciicast file format (version 1) 2 | 3 | asciicast file is JSON file containing meta-data like duration or title of the 4 | recording, and the actual content printed to terminal's stdout during 5 | recording. 6 | 7 | ## Attributes 8 | 9 | Every asciicast includes the following set of attributes: 10 | 11 | * `version` - set to 1, 12 | * `width` - terminal width (number of columns), 13 | * `height` - terminal height (number of rows), 14 | * `duration` - total duration of asciicast as floating point number, 15 | * `command` - command that was recorded, as given via `-c` option to `rec`, 16 | * `title` - title of the asciicast, as given via `-t` option to `rec`, 17 | * `env` - map of environment variables useful for debugging playback problems, 18 | * `stdout` - array of "frames", see below. 19 | 20 | ### Frame 21 | 22 | Frame represents an event of printing new data to terminal's stdout. It is a 2 23 | element array containing **delay** and **data**. 24 | 25 | **Delay** is the number of seconds that elapsed since the previous frame (or 26 | since the beginning of the recording in case of the 1st frame) represented as 27 | a floating point number, with microsecond precision. 28 | 29 | **Data** is a string containing the data that was printed to a terminal in a 30 | given frame. It has to be valid, UTF-8 encoded JSON string as described in 31 | [JSON RFC section 2.5](http://www.ietf.org/rfc/rfc4627.txt), with all 32 | non-printable Unicode codepoints encoded as `\uXXXX`. 33 | 34 | For example, frame `[5.4321, "foo\rbar\u0007..."]` means there was 5 seconds of 35 | inactivity between previous printing and printing of `foo\rbar\u0007...`. 36 | 37 | ## Example asciicast 38 | 39 | A very short asciicast may look like this: 40 | 41 | { 42 | "version": 1, 43 | "width": 80, 44 | "height": 24, 45 | "duration": 1.515658, 46 | "command": "/bin/zsh", 47 | "title": "", 48 | "env": { 49 | "TERM": "xterm-256color", 50 | "SHELL": "/bin/zsh" 51 | }, 52 | "stdout": [ 53 | [ 54 | 0.248848, 55 | "\u001b[1;31mHello \u001b[32mWorld!\u001b[0m\n" 56 | ], 57 | [ 58 | 1.001376, 59 | "I am \rThis is on the next line." 60 | ] 61 | ] 62 | } 63 | -------------------------------------------------------------------------------- /asciinema/commands/record.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import tempfile 4 | 5 | from asciinema.commands.command import Command 6 | from asciinema.recorder import Recorder 7 | from asciinema.api import APIError 8 | 9 | 10 | class RecordCommand(Command): 11 | 12 | def __init__(self, api, filename, command, title, assume_yes, quiet, max_wait, recorder=None): 13 | Command.__init__(self, quiet) 14 | self.api = api 15 | self.filename = filename 16 | self.command = command 17 | self.title = title 18 | self.assume_yes = assume_yes or quiet 19 | self.max_wait = max_wait 20 | self.recorder = recorder if recorder is not None else Recorder() 21 | 22 | def execute(self): 23 | if self.filename == "": 24 | self.filename = _tmp_path() 25 | upload = True 26 | else: 27 | upload = False 28 | 29 | try: 30 | _touch(self.filename) 31 | except OSError as e: 32 | self.print_warning("Can't record to %s: %s" % (self.filename, str(e))) 33 | return 1 34 | 35 | self.print_info("Asciicast recording started.") 36 | self.print_info("""Hit Ctrl-D or type "exit" to finish.""") 37 | 38 | self.recorder.record(self.filename, self.command, self.title, self.max_wait) 39 | 40 | self.print_info("Asciicast recording finished.") 41 | 42 | if upload: 43 | if not self.assume_yes: 44 | self.print_info("Press to upload, to cancel.") 45 | try: 46 | sys.stdin.readline() 47 | except KeyboardInterrupt: 48 | return 0 49 | 50 | try: 51 | url, warn = self.api.upload_asciicast(self.filename) 52 | if warn: 53 | self.print_warning(warn) 54 | os.remove(self.filename) 55 | self.print(url) 56 | except APIError as e: 57 | self.print_warning("Upload failed: %s" % str(e)) 58 | self.print_warning("Retry later by running: asciinema upload %s" % self.filename) 59 | return 1 60 | 61 | return 0 62 | 63 | 64 | def _tmp_path(): 65 | fd, path = tempfile.mkstemp(suffix='-asciinema.json') 66 | os.close(fd) 67 | return path 68 | 69 | 70 | def _touch(path): 71 | open(path, 'a').close() 72 | -------------------------------------------------------------------------------- /asciinema/api.py: -------------------------------------------------------------------------------- 1 | import platform 2 | import re 3 | 4 | from asciinema import __version__ 5 | from asciinema.urllib_http_adapter import URLLibHttpAdapter 6 | from asciinema.http_adapter import HTTPConnectionError 7 | 8 | 9 | class APIError(Exception): 10 | pass 11 | 12 | 13 | class Api: 14 | 15 | def __init__(self, url, user, token, http_adapter=None): 16 | self.url = url 17 | self.user = user 18 | self.token = token 19 | self.http_adapter = http_adapter if http_adapter is not None else URLLibHttpAdapter() 20 | 21 | def auth_url(self): 22 | return "{}/connect/{}".format(self.url, self.token) 23 | 24 | def upload_url(self): 25 | return "{}/api/asciicasts".format(self.url) 26 | 27 | def upload_asciicast(self, path): 28 | with open(path, 'rb') as f: 29 | try: 30 | status, headers, body = self.http_adapter.post( 31 | self.upload_url(), 32 | files={"asciicast": ("asciicast.json", f)}, 33 | headers=self._headers(), 34 | username=self.user, 35 | password=self.token 36 | ) 37 | except HTTPConnectionError as e: 38 | raise APIError(str(e)) 39 | 40 | if status != 200 and status != 201: 41 | self._handle_error(status, body) 42 | 43 | return body, headers.get('Warning') 44 | 45 | def _headers(self): 46 | return {'User-Agent': self._user_agent()} 47 | 48 | def _user_agent(self): 49 | os = re.sub('([^-]+)-(.*)', '\\1/\\2', platform.platform()) 50 | 51 | return 'asciinema/%s %s/%s %s' % (__version__, 52 | platform.python_implementation(), 53 | platform.python_version(), 54 | os 55 | ) 56 | 57 | def _handle_error(self, status, body): 58 | errors = { 59 | 400: "Invalid request: %s" % body, 60 | 401: "Invalid or revoked recorder token", 61 | 404: "API endpoint not found. This asciinema version may no longer be supported. Please upgrade to the latest version.", 62 | 413: "Sorry, your asciicast is too big.", 63 | 422: "Invalid asciicast: %s" % body, 64 | 503: "The server is down for maintenance. Try again in a minute." 65 | } 66 | 67 | error = errors.get(status) 68 | 69 | if not error: 70 | if status >= 500: 71 | error = "The server is having temporary problems. Try again in a minute." 72 | else: 73 | error = "HTTP status: %i" % status 74 | 75 | raise APIError(error) 76 | -------------------------------------------------------------------------------- /asciinema/config.py: -------------------------------------------------------------------------------- 1 | import os 2 | import os.path as path 3 | import sys 4 | import uuid 5 | import configparser 6 | 7 | 8 | class ConfigError(Exception): 9 | pass 10 | 11 | 12 | DEFAULT_API_URL = 'https://asciinema.org' 13 | 14 | 15 | class Config: 16 | 17 | def __init__(self, config, env=None): 18 | self.config = config 19 | self.env = env if env is not None else os.environ 20 | 21 | @property 22 | def api_url(self): 23 | return self.env.get( 24 | 'ASCIINEMA_API_URL', 25 | self.config.get('api', 'url', fallback=DEFAULT_API_URL) 26 | ) 27 | 28 | @property 29 | def api_token(self): 30 | try: 31 | return self.env.get('ASCIINEMA_API_TOKEN') or self.config.get('api', 'token') 32 | except (configparser.NoOptionError, configparser.NoSectionError): 33 | try: 34 | return self.config.get('user', 'token') 35 | except (configparser.NoOptionError, configparser.NoSectionError): 36 | raise ConfigError('no API token found in config file, and ASCIINEMA_API_TOKEN is unset') 37 | 38 | @property 39 | def record_command(self): 40 | return self.config.get('record', 'command', fallback=None) 41 | 42 | @property 43 | def record_max_wait(self): 44 | return self.config.getfloat('record', 'maxwait', fallback=None) 45 | 46 | @property 47 | def record_yes(self): 48 | return self.config.getboolean('record', 'yes', fallback=False) 49 | 50 | @property 51 | def record_quiet(self): 52 | return self.config.getboolean('record', 'quiet', fallback=False) 53 | 54 | @property 55 | def play_max_wait(self): 56 | return self.config.getfloat('play', 'maxwait', fallback=None) 57 | 58 | @property 59 | def play_speed(self): 60 | return self.config.getfloat('play', 'speed', fallback=1.0) 61 | 62 | 63 | def load_file(paths): 64 | config = configparser.ConfigParser() 65 | read_paths = config.read(paths) 66 | 67 | if read_paths: 68 | return config 69 | 70 | 71 | def create_file(filename): 72 | config = configparser.ConfigParser() 73 | config['api'] = {} 74 | config['api']['token'] = str(uuid.uuid4()) 75 | 76 | if not path.exists(path.dirname(filename)): 77 | os.makedirs(path.dirname(filename)) 78 | 79 | with open(filename, 'w') as f: 80 | config.write(f) 81 | 82 | return config 83 | 84 | 85 | def load(env=os.environ): 86 | paths = [] 87 | 88 | asciinema_config_home = env.get("ASCIINEMA_CONFIG_HOME") 89 | xdg_config_home = env.get("XDG_CONFIG_HOME") 90 | home = env.get("HOME") 91 | 92 | if asciinema_config_home: 93 | paths.append(path.join(asciinema_config_home, "config")) 94 | elif xdg_config_home: 95 | paths.append(path.join(xdg_config_home, "asciinema", "config")) 96 | elif home: 97 | paths.append(path.join(home, ".asciinema", "config")) 98 | paths.append(path.join(home, ".config", "asciinema", "config")) 99 | else: 100 | raise Exception("need $ASCIINEMA_CONFIG_HOME or $XDG_CONFIG_HOME or $HOME") 101 | 102 | config = load_file(paths) or create_file(paths[-1]) 103 | 104 | return Config(config, env) 105 | -------------------------------------------------------------------------------- /asciinema/urllib_http_adapter.py: -------------------------------------------------------------------------------- 1 | import codecs 2 | import mimetypes 3 | import sys 4 | import uuid 5 | import io 6 | import base64 7 | 8 | from urllib.request import Request, urlopen 9 | from urllib.error import HTTPError, URLError 10 | from .http_adapter import HTTPConnectionError 11 | 12 | 13 | class MultipartFormdataEncoder: 14 | def __init__(self): 15 | self.boundary = uuid.uuid4().hex 16 | self.content_type = 'multipart/form-data; boundary={}'.format(self.boundary) 17 | 18 | @classmethod 19 | def u(cls, s): 20 | if sys.hexversion >= 0x03000000 and isinstance(s, bytes): 21 | s = s.decode('utf-8') 22 | return s 23 | 24 | def iter(self, fields, files): 25 | """ 26 | fields is a dict of {name: value} for regular form fields. 27 | files is a dict of {name: (filename, file-type)} for data to be uploaded as files 28 | Yield body's chunk as bytes 29 | """ 30 | encoder = codecs.getencoder('utf-8') 31 | for (key, value) in fields.items(): 32 | key = self.u(key) 33 | yield encoder('--{}\r\n'.format(self.boundary)) 34 | yield encoder(self.u('Content-Disposition: form-data; name="{}"\r\n').format(key)) 35 | yield encoder('\r\n') 36 | if isinstance(value, int) or isinstance(value, float): 37 | value = str(value) 38 | yield encoder(self.u(value)) 39 | yield encoder('\r\n') 40 | for (key, filename_and_f) in files.items(): 41 | filename, f = filename_and_f 42 | key = self.u(key) 43 | filename = self.u(filename) 44 | yield encoder('--{}\r\n'.format(self.boundary)) 45 | yield encoder(self.u('Content-Disposition: form-data; name="{}"; filename="{}"\r\n').format(key, filename)) 46 | yield encoder('Content-Type: {}\r\n'.format(mimetypes.guess_type(filename)[0] or 'application/octet-stream')) 47 | yield encoder('\r\n') 48 | data = f.read() 49 | yield (data, len(data)) 50 | yield encoder('\r\n') 51 | yield encoder('--{}--\r\n'.format(self.boundary)) 52 | 53 | def encode(self, fields, files): 54 | body = io.BytesIO() 55 | for chunk, chunk_len in self.iter(fields, files): 56 | body.write(chunk) 57 | return self.content_type, body.getvalue() 58 | 59 | 60 | class URLLibHttpAdapter: 61 | 62 | def post(self, url, fields={}, files={}, headers={}, username=None, password=None): 63 | content_type, body = MultipartFormdataEncoder().encode(fields, files) 64 | 65 | headers = headers.copy() 66 | headers["Content-Type"] = content_type 67 | 68 | if password: 69 | auth = "%s:%s" % (username, password) 70 | encoded_auth = base64.encodestring(auth.encode('utf-8'))[:-1] 71 | headers["Authorization"] = b"Basic %" + encoded_auth 72 | 73 | request = Request(url, data=body, headers=headers, method="POST") 74 | 75 | try: 76 | response = urlopen(request) 77 | status = response.status 78 | headers = self._parse_headers(response) 79 | body = response.read().decode('utf-8') 80 | except HTTPError as e: 81 | status = e.code 82 | headers = {} 83 | body = e.read().decode('utf-8') 84 | except URLError as e: 85 | raise HTTPConnectionError(str(e)) 86 | 87 | return (status, headers, body) 88 | 89 | def _parse_headers(self, response): 90 | headers = {} 91 | for k, v in response.getheaders(): 92 | headers[k] = v 93 | 94 | return headers 95 | -------------------------------------------------------------------------------- /tests/config_test.py: -------------------------------------------------------------------------------- 1 | from nose.tools import assert_equal, assert_raises 2 | 3 | import os 4 | import tempfile 5 | import re 6 | 7 | import asciinema.config as cfg 8 | 9 | 10 | def create_config(content='', env={}): 11 | dir = tempfile.mkdtemp() 12 | path = dir + '/config' 13 | 14 | with open(path, 'w') as f: 15 | f.write(content) 16 | 17 | return cfg.Config(cfg.load_file([path]), env) 18 | 19 | 20 | def test_load_config(): 21 | with tempfile.TemporaryDirectory() as dir: 22 | config = cfg.load({'ASCIINEMA_CONFIG_HOME': dir + '/foo/bar'}) 23 | assert re.match('^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}', config.api_token) 24 | 25 | with open(dir + '/config', 'w') as f: 26 | token = 'foo-bar-baz-qux-quux' 27 | f.write("[api]\ntoken = %s" % token) 28 | 29 | config = cfg.load({'ASCIINEMA_CONFIG_HOME': dir}) 30 | assert_equal(token, config.api_token) 31 | 32 | 33 | def test_default_api_url(): 34 | config = create_config('') 35 | assert_equal('https://asciinema.org', config.api_url) 36 | 37 | 38 | def test_default_record_command(): 39 | config = create_config('') 40 | assert_equal(None, config.record_command) 41 | 42 | 43 | def test_default_record_max_wait(): 44 | config = create_config('') 45 | assert_equal(None, config.record_max_wait) 46 | 47 | 48 | def test_default_record_yes(): 49 | config = create_config('') 50 | assert_equal(False, config.record_yes) 51 | 52 | 53 | def test_default_record_quiet(): 54 | config = create_config('') 55 | assert_equal(False, config.record_quiet) 56 | 57 | 58 | def test_default_play_max_wait(): 59 | config = create_config('') 60 | assert_equal(None, config.play_max_wait) 61 | 62 | 63 | def test_api_url(): 64 | config = create_config("[api]\nurl = http://the/url") 65 | assert_equal('http://the/url', config.api_url) 66 | 67 | 68 | def test_api_url_when_override_set(): 69 | config = create_config("[api]\nurl = http://the/url", { 70 | 'ASCIINEMA_API_URL': 'http://the/url2'}) 71 | assert_equal('http://the/url2', config.api_url) 72 | 73 | 74 | def test_api_token(): 75 | token = 'foo-bar-baz' 76 | config = create_config("[api]\ntoken = %s" % token) 77 | assert re.match(token, config.api_token) 78 | 79 | 80 | def test_api_token_when_no_api_token_set(): 81 | config = create_config('') 82 | with assert_raises(Exception): 83 | config.api_token 84 | 85 | 86 | def test_api_token_when_user_token_set(): 87 | token = 'foo-bar-baz' 88 | config = create_config("[user]\ntoken = %s" % token) 89 | assert re.match(token, config.api_token) 90 | 91 | 92 | def test_api_token_when_api_token_set_and_user_token_set(): 93 | user_token = 'foo' 94 | api_token = 'bar' 95 | config = create_config("[user]\ntoken = %s\n[api]\ntoken = %s" % (user_token, api_token)) 96 | assert re.match(api_token, config.api_token) 97 | 98 | 99 | def test_record_command(): 100 | command = 'bash -l' 101 | config = create_config("[record]\ncommand = %s" % command) 102 | assert_equal(command, config.record_command) 103 | 104 | 105 | def test_record_max_wait(): 106 | max_wait = '2.35' 107 | config = create_config("[record]\nmaxwait = %s" % max_wait) 108 | assert_equal(2.35, config.record_max_wait) 109 | 110 | 111 | def test_record_yes(): 112 | yes = 'yes' 113 | config = create_config("[record]\nyes = %s" % yes) 114 | assert_equal(True, config.record_yes) 115 | 116 | 117 | def test_record_quiet(): 118 | quiet = 'yes' 119 | config = create_config("[record]\nquiet = %s" % quiet) 120 | assert_equal(True, config.record_quiet) 121 | 122 | 123 | def test_play_max_wait(): 124 | max_wait = '2.35' 125 | config = create_config("[play]\nmaxwait = %s" % max_wait) 126 | assert_equal(2.35, config.play_max_wait) 127 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to asciinema 2 | 3 | First, if you're opening a Github issue make sure it goes to the correct repository: 4 | 5 | * [asciinema/asciinema](https://github.com/asciinema/asciinema/issues) - command-line recorder 6 | * [asciinema/asciinema.org](https://github.com/asciinema/asciinema.org/issues) - public website hosting recordings 7 | * [asciinema/asciinema-player](https://github.com/asciinema/asciinema-player/issues) - player 8 | 9 | ## Reporting bugs 10 | 11 | Open an issue in Github issue tracker. 12 | Tell us what's the problem and include steps to reproduce it (reliably). 13 | Including your OS/browser/terminal name and version in the report would be great. 14 | 15 | ## Submitting patches with bug fixes 16 | 17 | If you found a bug and made a patch for it: 18 | 19 | * make sure all tests pass 20 | * send us a pull request, including a description of the fix (referencing an existing issue if there's one) 21 | 22 | ## Requesting new features 23 | 24 | We welcome all ideas. 25 | If you believe most asciinema users would benefit from implementing your idea then feel free to open a Github issue. 26 | However, as this is an open-source project maintained by a small team of volunteers we simply can't implement all of them due to limited resources. Please keep that in mind. 27 | 28 | ## Proposing features/changes (pull requests) 29 | 30 | If you want to propose code change, either introducing a new feature or improving an existing one, please first discuss this with asciinema team. You can simply open a separate issue for a discussion or join #asciinema IRC channel on freenode. 31 | 32 | ## Asking for help 33 | 34 | Github issue tracker is not a support forum. 35 | If you need help then either join #asciinema IRC channel on freenode or drop us an email at support@asciinema.org. 36 | 37 | ## Reporting security issues 38 | 39 | If you found a security issue in asciinema please contact us at support@asciinema.org. 40 | For the benefit of all asciinema users please **do not** publish details of the vulnerability in a Github issue. 41 | 42 | The PGP key below (1eb33a8760dec34b) can be used when sending encrypted email to or verifying responses from support@asciinema.org. 43 | 44 | ``` 45 | -----BEGIN PGP PUBLIC KEY BLOCK----- 46 | Version: GnuPG v2 47 | 48 | mQENBFRH/yQBCADwC8fadhrTTqCFEcQ8ex82FE24b2frRC3fvkFeKsY+v2lniYmZ 49 | wJ+qsd3cEv5uctCl+lQjrqhJrBx5DnZpCMw85vNuOhz/wjzn7efTISUF+HlnhiZd 50 | tN3FPbk4uu+1JiiZ7SEvH+I4JjM46Vx6wPZ9en79u8VPMLJ24F81Rar62oiMuL29 51 | PGV7CdG+ErUHEQfN1qLaZNQqkPCQSAouxooNqXKjs/mmz2651FrP8TKVr2f6B/2O 52 | YJ++H9SoIp7Ly+/fEjgmdaZnGqfxnBC+Pm82tZguprWeh8pdiu9ieJswr4S9tRms 53 | h2+eht8PWwkaOOhcFdZLnJFoXHOPzHilQVutABEBAAG0KUFzY2lpbmVtYSBTdXBw 54 | b3J0IDxzdXBwb3J0QGFzY2lpbmVtYS5vcmc+iQE4BBMBAgAiBQJUR/8kAhsDBgsJ 55 | CAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRAeszqHYN7DSyCeCADS9Jk7Ibl2f+2K 56 | eZ4XmYU0UxU55EtHZBd34yF+FGbl4doQhnKcRqT5lKLfYk4x3LzzPAHNSbRS05/K 57 | fw8l72GLHY01U/3slAixphIR8LwVyqPxwelTqLzkDvcK1TTTFnOM/XUT1ymNUS7i 58 | 6Bs889I4I8bPrnt1XK+W35/SqZbBAWotdidCbI/oKQgffCbVsH/Im5pnXTapvf/l 59 | sRUpB2fp7vD5+ycKDcB5CqbtnsPU9vCPL11GG3ijwQBgnPc0fKanUHb3IMElQ0ju 60 | 8IYTZjpPe7bIV3V3nYZvdO41IYLCHhRpvNt4BO2amQoGyqTqGHr/rCY1aEToDG2c 61 | cOdsEOmuuQENBFRH/yQBCACsR59NPSwGoK4zGgzDjuY7yLab2Tq1Jg1c038lA23G 62 | t3H9aOpVbeYGvDPYLHi2y1cCNv19nzs5/k/LAflhTcgPjipTHQ2ojDG+MNfO4qyH 63 | 3JFhm1WUw6zxFjBXfsZhoCKTNHZkzH+d0jeutbBq/Rd77sLjN/VVTLfzJCZhyhKD 64 | VEyO6DYaANZn1B/xx84WdxqqiQsLELOCQVUCG7HzbQAmx7lYYIUAwUoFTrBeBd+d 65 | sN7htw3j7le99EiccqMXceZd2W9cAlRfXcjHtvbtkbJTcsvANSUSU10q5uuT3f6l 66 | NftTLWOGZnu/rFU/ow5ipKft0ygfJKpMHD+AoLkiRIajABEBAAGJAR8EGAECAAkF 67 | AlRH/yQCGwwACgkQHrM6h2Dew0tG1wgAqOkkSznwF+6muK88GgrgasqnIq2t2VkN 68 | fTEKmykgSuMxiN4bsNLc4FQECZqIcL7zGuD6fFnsnO6Hg36R4rYGFSEsjjN7rXj0 69 | QLnrJJLZV0oA6Q77fUqdB0he7uJm+nlQjUv8HNJwp1oIyhhHz/r1kTHUlX+bEMO3 70 | Khc96UnE7nzwPBCbUvKuHJQY6K2ms1wgr9ELXjF1KVU9QtBtG2/XWRGDHDwQKxnW 71 | +2pRVtn2xNJ9rBipGG86ZU88vurYjgPZrXaex3M1QGD/8+9Wlp/TR7YUzjiZbtwc 72 | 6mpG4SUlwZheX9RbTRdjnLr7Qy+CddOWvGxebgk23/U90KrDyHDHig== 73 | =2M/2 74 | -----END PGP PUBLIC KEY BLOCK----- 75 | ``` 76 | -------------------------------------------------------------------------------- /asciinema/asciicast.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import json 3 | import json.decoder 4 | import urllib.request 5 | import urllib.error 6 | import html.parser 7 | from .stdout import Stdout 8 | 9 | 10 | class Asciicast: 11 | 12 | def __init__(self, stdout, width, height, duration, command=None, title=None, term=None, shell=None): 13 | self.stdout = stdout 14 | self.width = width 15 | self.height = height 16 | self.duration = duration 17 | self.command = command 18 | self.title = title 19 | self.term = term 20 | self.shell = shell 21 | 22 | def save(self, path): 23 | stdout = list(map(lambda frame: [round(frame[0], 6), frame[1]], self.stdout.frames)) 24 | duration = round(self.duration, 6) 25 | attrs = { 26 | "version": 1, 27 | "width": self.width, 28 | "height": self.height, 29 | "duration": duration, 30 | "command": self.command, 31 | "title": self.title, 32 | "env": { 33 | "TERM": self.term, 34 | "SHELL": self.shell 35 | }, 36 | "stdout": stdout 37 | } 38 | 39 | with open(path, "w") as f: 40 | f.write(json.dumps(attrs, ensure_ascii=False, indent=2)) 41 | 42 | 43 | # asciinema play file.json 44 | # asciinema play https://asciinema.org/a/123.json 45 | # asciinema play https://asciinema.org/a/123 46 | # asciinema play ipfs://ipfs/QmbdpNCwqeZgnmAWBCQcs8u6Ts6P2ku97tfKAycE1XY88p 47 | # asciinema play - 48 | 49 | 50 | class LoadError(Exception): 51 | pass 52 | 53 | 54 | class Parser(html.parser.HTMLParser): 55 | def __init__(self): 56 | html.parser.HTMLParser.__init__(self) 57 | self.url = None 58 | 59 | def handle_starttag(self, tag, attrs_list): 60 | # look for 61 | if tag == 'link': 62 | attrs = {} 63 | for k, v in attrs_list: 64 | attrs[k] = v 65 | 66 | if attrs.get('rel') == 'alternate' and attrs.get('type') == 'application/asciicast+json': 67 | self.url = attrs.get('href') 68 | 69 | 70 | def fetch(url): 71 | if url.startswith("ipfs:/"): 72 | url = "https://ipfs.io/%s" % url[6:] 73 | elif url.startswith("fs:/"): 74 | url = "https://ipfs.io/%s" % url[4:] 75 | 76 | if url == "-": 77 | return sys.stdin.read() 78 | 79 | if url.startswith("http:") or url.startswith("https:"): 80 | response = urllib.request.urlopen(url) 81 | data = response.read().decode(errors='replace') 82 | 83 | content_type = response.headers['Content-Type'] 84 | if content_type and content_type.startswith('text/html'): 85 | parser = Parser() 86 | parser.feed(data) 87 | url = parser.url 88 | 89 | if not url: 90 | raise LoadError(""" not found in fetched HTML document""") 91 | 92 | return fetch(url) 93 | 94 | return data 95 | 96 | with open(url, 'r') as f: 97 | return f.read() 98 | 99 | 100 | def load(filename): 101 | try: 102 | attrs = json.loads(fetch(filename)) 103 | 104 | if type(attrs) != dict: 105 | raise LoadError('unsupported asciicast format') 106 | 107 | return Asciicast( 108 | attrs['stdout'], 109 | attrs['width'], 110 | attrs['height'], 111 | attrs['duration'], 112 | attrs['command'], 113 | attrs['title'] 114 | ) 115 | except (OSError, urllib.error.HTTPError) as e: 116 | raise LoadError(str(e)) 117 | except json.decoder.JSONDecodeError as e: 118 | raise LoadError('JSON decoding error: ' + str(e)) 119 | except KeyError as e: 120 | raise LoadError('asciicast is missing key ' + str(e)) 121 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # asciinema changelog 2 | 3 | ## 1.3.0 (2016-07-13) 4 | 5 | This release brings back the original Python implementation of asciinema. It's 6 | based on 0.9.8 codebase and adds all features and bug fixes that have been 7 | implemented in asciinema's Go version between 0.9.8 and 1.2.0. 8 | 9 | Other notable changes: 10 | 11 | * Zero dependencies! (other than Python 3) 12 | * Fixed crash when resizing terminal window during recording (#167) 13 | * Fixed upload from IPv6 hosts (#94) 14 | * Improved UTF-8 charset detection (#160) 15 | * `-q/--quiet` option can be saved in config file now 16 | * Final "logout" (produced by csh) is now removed from recorded stdout 17 | * `rec` command now tries to write to target path before starting recording 18 | 19 | ## 1.2.0 (2016-02-22) 20 | 21 | * Added playback from stdin: `cat demo.json | asciinema play -` 22 | * Added playback from IPFS: `asciinema play ipfs:/ipfs/QmcdXYJp6e4zNuimuGeWPwNMHQdxuqWmKx7NhZofQ1nw2V` 23 | * Added playback from asciicast page URL: `asciinema play https://asciinema.org/a/22124` 24 | * `-q/--quiet` option added to `rec` command 25 | * Fixed handling of partial UTF-8 sequences in recorded stdout 26 | * Final "exit" is now removed from recorded stdout 27 | * Longer operations like uploading/downloading show "spinner" 28 | 29 | ## 1.1.1 (2015-06-21) 30 | 31 | * Fixed putting terminal in raw mode (fixes ctrl-o in nano) 32 | 33 | ## 1.1.0 (2015-05-25) 34 | 35 | * `--max-wait` option is now also available for `play` command 36 | * Added support for compilation on FreeBSD 37 | * Improved locale/charset detection 38 | * Improved upload error messages 39 | * New config file location (with backwards compatibility) 40 | 41 | ## 1.0.0 (2015-03-12) 42 | 43 | * `--max-wait` and `--yes` options can be saved in config file 44 | * Support for displaying warning messages returned from API 45 | * Also, see changes for 1.0.0 release candidates below 46 | 47 | ## 1.0.0.rc2 (2015-03-08) 48 | 49 | * All dependencies are vendored now in Godeps dir 50 | * Help message includes all commands with their possible options 51 | * `-y` and `-t` options have longer alternatives: `--yes`, `--title` 52 | * `--max-wait` option has shorter alternative: `-w` 53 | * Import paths changed to `github.com/asciinema/asciinema` due to repository 54 | renaming 55 | * `-y` also suppresess "please resize terminal" prompt 56 | 57 | ## 1.0.0.rc1 (2015-03-02) 58 | 59 | * New [asciicast file format](doc/asciicast-v1.md) 60 | * `rec` command can now record to file 61 | * New commands: `play ` and `upload ` 62 | * UTF-8 native locale is now required 63 | * Added handling of status 413 and 422 by printing user friendly message 64 | 65 | ## 0.9.9 (2014-12-17) 66 | 67 | * Rewritten in Go 68 | * License changed to GPLv3 69 | * `--max-wait` option added to `rec` command 70 | * Recorded process has `ASCIINEMA_REC` env variable set (useful for "rec" 71 | indicator in shell's `$PROMPT/$RPROMPT`) 72 | * No more terminal resetting (via `reset` command) before and after recording 73 | * Informative messages are coloured to be distinguishable from normal output 74 | * Improved error messages 75 | 76 | ## 0.9.8 (2014-02-09) 77 | 78 | * Rename user_token to api_token 79 | * Improvements to test suite 80 | * Send User-Agent including client version number, python version and platform 81 | * Handle 503 status as server maintenance 82 | * Handle 404 response as a request for client upgrade 83 | 84 | ## 0.9.7 (2013-10-07) 85 | 86 | * Depend on requests==1.1.0, not 2.0 87 | 88 | ## 0.9.6 (2013-10-06) 89 | 90 | * Remove install script 91 | * Introduce proper python package: https://pypi.python.org/pypi/asciinema 92 | * Make the code compatible with both python 2 and 3 93 | * Use requests lib instead of urrlib(2) 94 | 95 | ## 0.9.5 (2013-10-04) 96 | 97 | * Fixed measurement of total recording time 98 | * Improvements to install script 99 | * Introduction of Homebrew formula 100 | 101 | ## 0.9.4 (2013-10-03) 102 | 103 | * Use python2.7 in shebang 104 | 105 | ## 0.9.3 (2013-10-03) 106 | 107 | * Re-enable resetting of a terminal before and after recording 108 | * Add Arch Linux source package 109 | 110 | ## 0.9.2 (2013-10-02) 111 | 112 | * Use os.uname over running the uname command 113 | * Add basic integration tests 114 | * Make PtyRecorder test stable again 115 | * Move install script out of bin dir 116 | 117 | ## 0.9.1 (2013-10-01) 118 | 119 | * Split monolithic script into separate classes/files 120 | * Remove upload queue 121 | * Use python2 in generated binary's shebang 122 | * Delay config file creation until user_token is requested 123 | * Introduce command classes for handling cli commands 124 | * Split the recorder into classes with well defined responsibilities 125 | * Drop curl dependency, use urllib(2) for http requests 126 | 127 | ## 0.9.0 (2013-09-24) 128 | 129 | * Project rename from "ascii.io" to "asciinema" 130 | 131 | ## ... limbo? ... 132 | 133 | ## 0.1 (2012-03-11) 134 | 135 | * Initial release 136 | -------------------------------------------------------------------------------- /asciinema/pty_recorder.py: -------------------------------------------------------------------------------- 1 | import errno 2 | import os 3 | import pty 4 | import signal 5 | import tty 6 | import array 7 | import fcntl 8 | import termios 9 | import select 10 | import io 11 | import shlex 12 | import sys 13 | import struct 14 | 15 | 16 | class PtyRecorder: 17 | 18 | def record_command(self, command, output, env=os.environ): 19 | master_fd = None 20 | 21 | def _set_pty_size(): 22 | ''' 23 | Sets the window size of the child pty based on the window size 24 | of our own controlling terminal. 25 | ''' 26 | 27 | # Get the terminal size of the real terminal, set it on the pseudoterminal. 28 | if os.isatty(pty.STDOUT_FILENO): 29 | buf = array.array('h', [0, 0, 0, 0]) 30 | fcntl.ioctl(pty.STDOUT_FILENO, termios.TIOCGWINSZ, buf, True) 31 | fcntl.ioctl(master_fd, termios.TIOCSWINSZ, buf) 32 | else: 33 | buf = array.array('h', [24, 80, 0, 0]) 34 | fcntl.ioctl(master_fd, termios.TIOCSWINSZ, buf) 35 | 36 | def _write_stdout(data): 37 | '''Writes to stdout as if the child process had written the data.''' 38 | 39 | os.write(pty.STDOUT_FILENO, data) 40 | 41 | def _handle_master_read(data): 42 | '''Handles new data on child process stdout.''' 43 | 44 | _write_stdout(data) 45 | output.write(data) 46 | 47 | def _write_master(data): 48 | '''Writes to the child process from its controlling terminal.''' 49 | 50 | while data: 51 | n = os.write(master_fd, data) 52 | data = data[n:] 53 | 54 | def _handle_stdin_read(data): 55 | '''Handles new data on child process stdin.''' 56 | 57 | _write_master(data) 58 | 59 | def _copy(signal_fd): 60 | '''Main select loop. 61 | 62 | Passes control to _master_read() or _stdin_read() 63 | when new data arrives. 64 | ''' 65 | 66 | fds = [master_fd, pty.STDIN_FILENO, signal_fd] 67 | 68 | while True: 69 | try: 70 | rfds, wfds, xfds = select.select(fds, [], []) 71 | except OSError as e: # Python >= 3.3 72 | if e.errno == errno.EINTR: 73 | continue 74 | except select.error as e: # Python < 3.3 75 | if e.args[0] == 4: 76 | continue 77 | 78 | if master_fd in rfds: 79 | data = os.read(master_fd, 1024) 80 | if not data: # Reached EOF. 81 | fds.remove(master_fd) 82 | else: 83 | _handle_master_read(data) 84 | 85 | if pty.STDIN_FILENO in rfds: 86 | data = os.read(pty.STDIN_FILENO, 1024) 87 | if not data: 88 | fds.remove(pty.STDIN_FILENO) 89 | else: 90 | _handle_stdin_read(data) 91 | 92 | if signal_fd in rfds: 93 | data = os.read(signal_fd, 1024) 94 | if data: 95 | signals = struct.unpack('%uB' % len(data), data) 96 | for sig in signals: 97 | if sig == signal.SIGCHLD: 98 | os.close(master_fd) 99 | return 100 | elif sig == signal.SIGWINCH: 101 | _set_pty_size() 102 | 103 | pid, master_fd = pty.fork() 104 | 105 | if pid == pty.CHILD: 106 | os.execvpe(command[0], command, env) 107 | 108 | pipe_r, pipe_w = os.pipe() 109 | flags = fcntl.fcntl(pipe_w, fcntl.F_GETFL, 0) 110 | flags = flags | os.O_NONBLOCK 111 | flags = fcntl.fcntl(pipe_w, fcntl.F_SETFL, flags) 112 | 113 | signal.set_wakeup_fd(pipe_w) 114 | 115 | old_sigwinch_handler = signal.signal(signal.SIGWINCH, lambda signal, frame: None) 116 | old_sigchld_handler = signal.signal(signal.SIGCHLD, lambda signal, frame: None) 117 | 118 | try: 119 | mode = tty.tcgetattr(pty.STDIN_FILENO) 120 | tty.setraw(pty.STDIN_FILENO) 121 | restore = 1 122 | except tty.error: # This is the same as termios.error 123 | restore = 0 124 | 125 | _set_pty_size() 126 | 127 | try: 128 | _copy(pipe_r) 129 | except (IOError, OSError): 130 | pass 131 | finally: 132 | if restore: 133 | tty.tcsetattr(pty.STDIN_FILENO, tty.TCSAFLUSH, mode) 134 | 135 | signal.signal(signal.SIGWINCH, old_sigwinch_handler) 136 | signal.signal(signal.SIGCHLD, old_sigchld_handler) 137 | 138 | os.waitpid(pid, 0) 139 | output.close() 140 | -------------------------------------------------------------------------------- /man/asciinema.1: -------------------------------------------------------------------------------- 1 | .TH "asciinema" "1" "July 13, 2016" "asciinema 1.3.0" 2 | .SH "NAME" 3 | asciinema \- terminal session recorder 4 | .SH "SYNOPSIS" 5 | .B asciinema 6 | .I [\-h] [\-\-version] command [] 7 | .SH "DESCRIPTION" 8 | Terminal session recorder and the best companion of asciinema.org service. 9 | .PP 10 | asciinema is composed of multiple commands, similar to git, apt-get or brew. 11 | .PP 12 | When you run asciinema with no arguments help messages is displayed, listing all available commands with their options. 13 | .SH "OPTIONS" 14 | .TP 15 | \-h, \-\-help 16 | Display help message 17 | .TP 18 | \-\-version 19 | Display version information 20 | .SH "COMMANDS" 21 | .B rec [] 22 | .RS 4 23 | Record terminal session. 24 | .PP 25 | This is the single most important command in asciinema, since it is how you utilize this tool's main job. 26 | .PP 27 | By running \fBasciinema rec\fP \fI[filename]\fP you start a new recording session. The command (process) that is recorded can be specified with \fI-c\fP option (see below), and defaults to \fB$SHELL\fP which is what you want in most cases. 28 | .PP 29 | Recording finishes when you exit the shell (hit \fBCtrl+D\fP or type \fIexit\fP). If the recorded process is not a shell than recording finishes when the process exits. 30 | .PP 31 | If the \fIfilename\fP argument is given then the resulting recording is saved to a local file. It can later be replayed with \fBasciinema play\fP \fI\fP and/or uploaded to asciinema.org with \fBasciinema upload\fP \fI\fP. If the \fIfilename\fP argument is omitted then (after asking for confirmation) the resulting asciicast is uploaded to asciinema.org for further playback in a web browser. 32 | .PP 33 | \fBASCIINEMA_REC=1\fP is added to recorded process environment variables. This can be used by your shell's config file (\fI.bashrc\fP, \fI.zshrc\fP) to alter the prompt or play a sound when shell is being recorded. 34 | .TP 35 | Available options: 36 | .RS 4 37 | .TP 38 | \-c, \-\-command 39 | specify command to record, defaults to $SHELL 40 | .TP 41 | \-t 42 | specify the title of the asciicast 43 | .TP 44 | \-w, \-\-max\-wait 45 | reduce recorded terminal inactivity to max seconds 46 | .TP 47 | \-y, \-\-yes 48 | answer "yes" to all prompts (e.g. upload confirmation) 49 | .TP 50 | \-q, \-\-quiet 51 | be quiet, suppress all notices/warnings (implies -y) 52 | .RE 53 | .RE 54 | .PP 55 | .B play 56 | .RS 4 57 | Replay recorded asciicast in a terminal. 58 | .PP 59 | This command replays given asciicast (as recorded by \fIrec\fP command) directly in your terminal. 60 | .PP 61 | When "-" is passed as a filename the asciicast is read from stdin. 62 | .PP 63 | NOTE: it is recommended to run it in a terminal of dimensions not smaller than the one used for recording as there's no "transcoding" of control sequences for new terminal size. 64 | .TP 65 | Available options: 66 | .RS 4 67 | .TP 68 | \-w, \-\-max\-wait 69 | reduce replayed terminal inactivity to max \fIsec\fP seconds 70 | .TP 71 | \-s, \-\-speed 72 | speed up playback by factor \fIfactor\fP (can be fractional) 73 | .RE 74 | .RE 75 | .PP 76 | .B upload 77 | .RS 4 78 | Upload recorded asciicast to asciinema.org site. 79 | .PP 80 | This command uploads given asciicast (as recorded by \fIrec\fP command) to asciinema.org for further playback in a web browser. 81 | .PP 82 | \fBasciinema rec\fP \fIdemo.json\fP + \fBasciinema play\fP \fIdemo.json\fP + \fBasciinema upload\fP \fIdemo.json\fP is a nice combo for when you want to review an asciicast before publishing it on asciinema.org. 83 | .RE 84 | .PP 85 | .B auth 86 | .RS 4 87 | Assign local API token to asciinema.org account. 88 | .PP 89 | On every machine you install asciinema recorder, you get a new, unique API 90 | token. This command connects this local token with your asciinema.org account, 91 | and links all asciicasts recorded on this machine with the account. 92 | .PP 93 | This command displays the URL you should open in your web browser. If you never 94 | logged in to asciinema.org then your account will be created when opening the 95 | URL. 96 | .PP 97 | NOTE: it is \fBnecessary\fP to do this if you want to edit or delete your 98 | recordings on asciinema.org. 99 | .PP 100 | You can synchronize your config file (which keeps the API token) across the 101 | machines but that's not necessary. You can assign new tokens to your account 102 | from as many machines as you want. 103 | .RE 104 | .SH "CONTRIBUTING" 105 | If you want to contribute to this project check out Contributing page: \fIhttps://asciinema.org/contributing\fP 106 | .SH "BUGS" 107 | All your bug reports and feature ideas are highly appreciated as they help to improve the quality and functionality of asciinema for everyone. 108 | .PP 109 | As the service is built of several parts there are separate bug trackers: 110 | .TP 111 | https://github.com/asciinema/asciinema/issues 112 | issues and ideas for the command line recorder 113 | .TP 114 | https://github.com/asciinema/asciinema.org/issues 115 | issues and ideas for the website 116 | .TP 117 | https://github.com/asciinema/asciinema-player/issues 118 | issues and ideas for the javascript player 119 | .SH "AUTHORS" 120 | Developed with passion by \fBMarcin Kulik\fP and great open source contributors. 121 | -------------------------------------------------------------------------------- /asciinema/__main__.py: -------------------------------------------------------------------------------- 1 | import locale 2 | import argparse 3 | import os 4 | import sys 5 | 6 | from asciinema import __version__ 7 | import asciinema.config as config 8 | from asciinema.commands.auth import AuthCommand 9 | from asciinema.commands.record import RecordCommand 10 | from asciinema.commands.play import PlayCommand 11 | from asciinema.commands.upload import UploadCommand 12 | from asciinema.api import Api 13 | 14 | 15 | def positive_float(value): 16 | value = float(value) 17 | if value <= 0.0: 18 | raise argparse.ArgumentTypeError("must be positive") 19 | 20 | return value 21 | 22 | 23 | def rec_command(args, config): 24 | api = Api(config.api_url, os.environ.get("USER"), config.api_token) 25 | return RecordCommand(api, args.filename, args.command, args.title, args.yes, args.quiet, args.max_wait) 26 | 27 | 28 | def play_command(args, config): 29 | return PlayCommand(args.filename, args.max_wait, args.speed) 30 | 31 | 32 | def upload_command(args, config): 33 | api = Api(config.api_url, os.environ.get("USER"), config.api_token) 34 | return UploadCommand(api, args.filename) 35 | 36 | 37 | def auth_command(args, config): 38 | return AuthCommand(config.api_url, config.api_token) 39 | 40 | 41 | def maybe_str(v): 42 | if v is not None: 43 | return str(v) 44 | 45 | 46 | def main(): 47 | if locale.nl_langinfo(locale.CODESET).upper() != 'UTF-8': 48 | print("asciinema needs a UTF-8 native locale to run. Check the output of `locale` command.") 49 | sys.exit(1) 50 | 51 | cfg = config.load() 52 | 53 | # create the top-level parser 54 | parser = argparse.ArgumentParser( 55 | description="Record and share your terminal sessions, the right way.", 56 | epilog="""example usage: 57 | Record terminal and upload it to asciinema.org: 58 | \x1b[1masciinema rec\x1b[0m 59 | Record terminal to local file: 60 | \x1b[1masciinema rec demo.json\x1b[0m 61 | Record terminal and upload it to asciinema.org, specifying title: 62 | \x1b[1masciinema rec -t "My git tutorial"\x1b[0m 63 | Record terminal to local file, "trimming" longer pauses to max 2.5 sec: 64 | \x1b[1masciinema rec -w 2.5 demo.json\x1b[0m 65 | Replay terminal recording from local file: 66 | \x1b[1masciinema play demo.json\x1b[0m 67 | Replay terminal recording hosted on asciinema.org: 68 | \x1b[1masciinema play https://asciinema.org/a/difqlgx86ym6emrmd8u62yqu8\x1b[0m 69 | 70 | For help on a specific command run: 71 | \x1b[1masciinema -h\x1b[0m""", 72 | formatter_class=argparse.RawDescriptionHelpFormatter 73 | ) 74 | parser.add_argument('--version', action='version', version='asciinema %s' % __version__) 75 | 76 | subparsers = parser.add_subparsers() 77 | 78 | # create the parser for the "rec" command 79 | parser_rec = subparsers.add_parser('rec', help='Record terminal session') 80 | parser_rec.add_argument('-c', '--command', help='command to record, defaults to $SHELL', default=cfg.record_command) 81 | parser_rec.add_argument('-t', '--title', help='title of the asciicast') 82 | parser_rec.add_argument('-w', '--max-wait', help='limit recorded terminal inactivity to max seconds (can be fractional)', type=positive_float, default=maybe_str(cfg.record_max_wait)) 83 | parser_rec.add_argument('-y', '--yes', help='answer "yes" to all prompts (e.g. upload confirmation)', action='store_true', default=cfg.record_yes) 84 | parser_rec.add_argument('-q', '--quiet', help='be quiet, suppress all notices/warnings (implies -y)', action='store_true', default=cfg.record_quiet) 85 | parser_rec.add_argument('filename', nargs='?', default='', help='filename/path to save the recording to') 86 | parser_rec.set_defaults(func=rec_command) 87 | 88 | # create the parser for the "play" command 89 | parser_play = subparsers.add_parser('play', help='Replay terminal session') 90 | parser_play.add_argument('-w', '--max-wait', help='limit terminal inactivity to max seconds (can be fractional)', type=positive_float, default=maybe_str(cfg.play_max_wait)) 91 | parser_play.add_argument('-s', '--speed', help='playback speedup (can be fractional)', type=positive_float, default=cfg.play_speed) 92 | parser_play.add_argument('filename', help='local path, http/ipfs URL or "-" (read from stdin)') 93 | parser_play.set_defaults(func=play_command) 94 | 95 | # create the parser for the "upload" command 96 | parser_upload = subparsers.add_parser('upload', help='Upload locally saved terminal session to asciinema.org') 97 | parser_upload.add_argument('filename', help='filename or path of local recording') 98 | parser_upload.set_defaults(func=upload_command) 99 | 100 | # create the parser for the "auth" command 101 | parser_auth = subparsers.add_parser('auth', help='Manage recordings on asciinema.org account') 102 | parser_auth.set_defaults(func=auth_command) 103 | 104 | # parse the args and call whatever function was selected 105 | args = parser.parse_args() 106 | 107 | if hasattr(args, 'func'): 108 | command = args.func(args, cfg) 109 | code = command.execute() 110 | sys.exit(code) 111 | else: 112 | parser.print_help() 113 | sys.exit(1) 114 | 115 | 116 | if __name__ == '__main__': 117 | main() 118 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # asciinema 2 | 3 | [![Build Status](https://travis-ci.org/asciinema/asciinema.svg?branch=master)](https://travis-ci.org/asciinema/asciinema) 4 | [![license](http://img.shields.io/badge/license-GNU-blue.svg)](https://raw.githubusercontent.com/asciinema/asciinema/master/LICENSE) 5 | 6 | Terminal session recorder and the best companion of 7 | [asciinema.org](https://asciinema.org). 8 | 9 | [![demo](https://asciinema.org/a/42383.png)](https://asciinema.org/a/42383?autoplay=1) 10 | 11 | ## Installation 12 | 13 | ### Native packages 14 | 15 | asciinema is included in repositories of most popular package managers on Mac OS 16 | X, Linux and FreeBSD. Look for package named `asciinema`. See the 17 | [list of available packages](https://asciinema.org/docs/installation). 18 | 19 | ### Python package 20 | 21 | asciinema is available on [PyPI](https://pypi.python.org/pypi/asciinema) and can 22 | be installed with pip (Python 3 required): 23 | 24 | sudo pip3 install asciinema 25 | 26 | ### Running latest version from master 27 | 28 | If none of the above works for you (or you want to help with development) just 29 | clone the repo and run asciinema straight from the checkout: 30 | 31 | git clone https://github.com/asciinema/asciinema.git 32 | cd asciinema 33 | python3 -m asciinema --version 34 | 35 | ## Usage 36 | 37 | asciinema is composed of multiple commands, similar to `git`, `apt-get` or 38 | `brew`. 39 | 40 | When you run `asciinema` with no arguments help message is displayed, listing 41 | all available commands with their options. 42 | 43 | ### `rec [filename]` 44 | 45 | __Record terminal session.__ 46 | 47 | This is the single most important command in asciinema, since it is how you 48 | utilize this tool's main job. 49 | 50 | By running `asciinema rec [filename]` you start a new recording session. The 51 | command (process) that is recorded can be specified with `-c` option (see 52 | below), and defaults to `$SHELL` which is what you want in most cases. 53 | 54 | Recording finishes when you exit the shell (hit Ctrl+D or type 55 | `exit`). If the recorded process is not a shell then recording finishes when 56 | the process exits. 57 | 58 | If the `filename` argument is given then the resulting recording (called 59 | [asciicast](doc/asciicast-v1.md)) is saved to a local file. It can later be 60 | replayed with `asciinema play ` and/or uploaded to asciinema.org with 61 | `asciinema upload `. If the `filename` argument is omitted then 62 | (after asking for confirmation) the resulting asciicast is uploaded to 63 | asciinema.org for further playback in a web browser. 64 | 65 | `ASCIINEMA_REC=1` is added to recorded process environment variables. This 66 | can be used by your shell's config file (`.bashrc`, `.zshrc`) to alter the 67 | prompt or play a sound when shell is being recorded. 68 | 69 | Available options: 70 | 71 | * `-c, --command=` - Specify command to record, defaults to $SHELL 72 | * `-t, --title=` - Specify the title of the asciicast 73 | * `-w, --max-wait=<sec>` - Reduce recorded terminal inactivity to max <sec> seconds 74 | * `-y, --yes` - Answer "yes" to all prompts (e.g. upload confirmation) 75 | * `-q, --quiet` - Be quiet, suppress all notices/warnings (implies -y) 76 | 77 | ### `play <filename>` 78 | 79 | __Replay recorded asciicast in a terminal.__ 80 | 81 | This command replays given asciicast (as recorded by `rec` command) directly in 82 | your terminal. 83 | 84 | Playing from a local file: 85 | 86 | asciinema play /path/to/asciicast.json 87 | 88 | Playing from HTTP(S) URL: 89 | 90 | asciinema play https://asciinema.org/a/22124.json 91 | asciinema play http://example.com/demo.json 92 | 93 | Playing from asciicast page URL (requires `<link rel="alternate" 94 | type="application/asciicast+json" href="....json">` in page's HTML): 95 | 96 | asciinema play https://asciinema.org/a/22124 97 | asciinema play http://example.com/blog/post.html 98 | 99 | Playing from stdin: 100 | 101 | cat /path/to/asciicast.json | asciinema play - 102 | ssh user@host cat asciicast.json | asciinema play - 103 | 104 | Playing from IPFS: 105 | 106 | asciinema play ipfs:/ipfs/QmcdXYJp6e4zNuimuGeWPwNMHQdxuqWmKx7NhZofQ1nw2V 107 | asciinema play fs:/ipfs/QmcdXYJp6e4zNuimuGeWPwNMHQdxuqWmKx7NhZofQ1nw2V 108 | 109 | Available options: 110 | 111 | * `-w, --max-wait=<sec>` - Reduce replayed terminal inactivity to max <sec> seconds 112 | * `-s, --speed=<factor>` - Playback speedup (can be fractional) 113 | 114 | NOTE: it is recommended to run `asciinema play` in a terminal of dimensions not 115 | smaller than the one used for recording as there's no "transcoding" of control 116 | sequences for new terminal size. 117 | 118 | ### `upload <filename>` 119 | 120 | __Upload recorded asciicast to asciinema.org site.__ 121 | 122 | This command uploads given asciicast (as recorded by `rec` command) to 123 | asciinema.org for further playback in a web browser. 124 | 125 | `asciinema rec demo.json` + `asciinema play demo.json` + `asciinema upload 126 | demo.json` is a nice combo for when you want to review an asciicast before 127 | publishing it on asciinema.org. 128 | 129 | ### `auth` 130 | 131 | __Manage recordings on asciinema.org account.__ 132 | 133 | If you want to manage your recordings on asciinema.org (set title/description, 134 | delete etc) you need to authenticate. This command displays the URL you should 135 | open in your web browser to do that. 136 | 137 | On every machine you run asciinema recorder, you get a new, unique API token. If 138 | you're already logged in on asciinema.org website and you run `asciinema auth` 139 | from a new computer then this new device will be linked to your account. 140 | 141 | You can synchronize your config file (which keeps the API token) across the 142 | machines so all of them use the same token, but that's not necessary. You can 143 | assign new tokens to your account from as many machines as you want. 144 | 145 | ## Hosting the recordings on the web 146 | 147 | As mentioned in the `Usage / rec` section above, if the `filename` argument to 148 | `asciinema rec` is omitted then the resulting asciicast is uploaded 149 | to [asciinema.org](https://asciinema.org) where it's hosted for further playback 150 | in a web browser. 151 | 152 | If you prefer to host the recordings yourself, you can do so by recording to a 153 | file (`asciinema rec demo.json`) and using 154 | [asciinema's standalone web player](https://github.com/asciinema/asciinema-player#self-hosting-quick-start) 155 | in your HTML page. 156 | 157 | ## Configuration file 158 | 159 | asciinema uses a config file to keep API token and user settings. In most cases 160 | the location of this file is `$HOME/.config/asciinema/config`. 161 | 162 | *NOTE: When you first run asciinema, local API token is generated (UUID) and 163 | saved in the file (unless the file already exists).* 164 | 165 | The auto-generated, minimal config file looks like this: 166 | 167 | [api] 168 | token = <your-api-token-here> 169 | 170 | There are several options you can set in this file. Here's a config with all 171 | available options set: 172 | 173 | [api] 174 | token = <your-api-token-here> 175 | url = https://asciinema.example.com 176 | 177 | [record] 178 | command = /bin/bash -l 179 | maxwait = 2 180 | yes = true 181 | quiet = true 182 | 183 | [play] 184 | maxwait = 1 185 | 186 | The options in `[api]` section are related to API location and authentication. 187 | To tell asciinema recorder to use your own asciinema site instance rather than 188 | the default one (asciinema.org), you can set `url` option. API URL can also be 189 | passed via `ASCIINEMA_API_URL` environment variable. 190 | 191 | The options in `[record]` and `[play]` sections have the same meaning as the 192 | options you pass to `asciinema rec`/`asciinema play` command. If you happen to 193 | often use either `-c`, `-w` or `-y` with these commands then consider saving it 194 | as a default in the config file. 195 | 196 | ### Configuration file locations 197 | 198 | In fact, the following locations are checked for the presence of the config 199 | file (in the given order): 200 | 201 | * `$ASCIINEMA_CONFIG_HOME/config` - if you have set `$ASCIINEMA_CONFIG_HOME` 202 | * `$XDG_CONFIG_HOME/asciinema/config` - on Linux, `$XDG_CONFIG_HOME` usually points to `$HOME/.config/` 203 | * `$HOME/.config/asciinema/config` - in most cases it's here 204 | * `$HOME/.asciinema/config` - created by asciinema versions prior to 1.1 205 | 206 | The first one found is used. 207 | 208 | ## Contributing 209 | 210 | If you want to contribute to this project check out 211 | [Contributing](https://asciinema.org/contributing) page. 212 | 213 | ## Authors 214 | 215 | Developed with passion by [Marcin Kulik](http://ku1ik.com) and great open 216 | source [contributors](https://github.com/asciinema/asciinema/contributors) 217 | 218 | ## License 219 | 220 | Copyright © 2011-2017 Marcin Kulik. 221 | 222 | All code is licensed under the GPL, v3 or later. See LICENSE file for details. 223 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | <one line to give the program's name and a brief idea of what it does.> 635 | Copyright (C) <year> <name of author> 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see <http://www.gnu.org/licenses/>. 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | <program> Copyright (C) <year> <name of author> 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | <http://www.gnu.org/licenses/>. 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | <http://www.gnu.org/philosophy/why-not-lgpl.html>. 675 | --------------------------------------------------------------------------------