def decktape(): '''Install DeckTape. DeckTape is a "high-quality PDF exporter for HTML5 presentation frameworks". It can be used to create PDFs from reveal.js presentations. More info: https://github.com/astefanutti/decktape https://github.com/hakimel/reveal.js/issues/1252#issuecomment-198270915 ''' run('mkdir -p ~/bin/decktape') if not exists('~/bin/decktape/decktape-1.0.0'): print_msg('\n## download decktape 1.0.0\n') run('cd ~/bin/decktape && ' 'curl -L https://github.com/astefanutti/decktape/archive/' 'v1.0.0.tar.gz | tar -xz --exclude phantomjs') run('cd ~/bin/decktape/decktape-1.0.0 && ' 'curl -L https://github.com/astefanutti/decktape/releases/' 'download/v1.0.0/phantomjs-linux-x86-64 -o phantomjs') run('cd ~/bin/decktape/decktape-1.0.0 && ' 'chmod +x phantomjs') run('ln -snf ~/bin/decktape/decktape-1.0.0 ~/bin/decktape/active', msg='\n## link installed decktape version as active') print_msg('\nCreate PDF from reveal.js presentation:\n\n ' '# serve presentation:\n ' 'cd ~/repos/my_presi/reveal.js/ && npm start\n\n ' '# create pdf in another shell:\n ' 'cd ~/bin/decktape/active && \\\n ' './phantomjs decktape.js --size 1280x800 localhost:8000 ' '~/repos/my_presi/my_presi.pdf')
def set_up_vim_addon_xmledit(): print_msg('\nenable *.html files for vim addon xmledit:') ftplugin_dir = '~/.janus/xmledit/ftplugin' if exists(ftplugin_dir): # enable html file support (cf. http://stackoverflow.com/a/28603924): run(flo('cp -n {ftplugin_dir}/html.vim {ftplugin_dir}/html.vim.orig')) run(flo('ln -snf xml.vim {ftplugin_dir}/html.vim'))
def revealjs(basedir=None, title=None, subtitle=None, description=None, github_user=None, github_repo=None): '''Set up or update a reveals.js presentation with slides written in markdown. Several reveal.js plugins will be set up, too. More info: Demo: https://theno.github.io/revealjs_template http://lab.hakim.se/reveal-js/ https://github.com/hakimel/reveal.js plugins: https://github.com/hakimel/reveal.js/wiki/Plugins,-Tools-and-Hardware https://github.com/rajgoel/reveal.js-plugins/ https://github.com/e-gor/Reveal.js-TOC-Progress https://github.com/e-gor/Reveal.js-Title-Footer ''' basedir = basedir or query_input('Base dir of the presentation?', default='~/repos/my_presi') revealjs_repo_name = 'reveal.js' revealjs_dir = flo('{basedir}/{revealjs_repo_name}') _lazy_dict['presi_title'] = title _lazy_dict['presi_subtitle'] = subtitle _lazy_dict['presi_description'] = description _lazy_dict['github_user'] = github_user _lazy_dict['github_repo'] = github_repo question = flo( "Base dir already contains a sub dir '{revealjs_repo_name}'." ' Reset (and re-download) reveal.js codebase?') if not exists(revealjs_dir) or query_yes_no(question, default='no'): run(flo('mkdir -p {basedir}')) set_up_revealjs_codebase(basedir, revealjs_repo_name) install_plugins(revealjs_dir) apply_customizations(repo_dir=revealjs_dir) if exists(revealjs_dir): install_files_in_basedir(basedir, repo_dir=revealjs_dir) init_git_repo(basedir) create_github_remote_repo(basedir) setup_npm(revealjs_dir) else: print('abort')
def export_repo(parent_dir, repo_url, repo_name=None): if repo_name: repo_dir = flo('{parent_dir}/{repo_name}') if exists(repo_dir): run(flo('rm -rf {repo_dir}'), msg='delete existing repo dir') repo_name = checkup_git_repo_legacy(repo_url, name=repo_name, base_dir=parent_dir) run(flo('cd {parent_dir}/{repo_name} && rm -rf .git/'), msg='delete .git dir (the hole presentation becomes a git repository)')
def uninstall_janus(): '''Remove all janus files and dirs and (try to) restore previous vim config. ''' if exists('~/.vim/janus'): run('rm -rf ~/.vim', msg='delete janus repo dir') with warn_only(): run('rm -rf ~/.janus', msg='delete ~/.janus dir') run('bash -c "rm ~/.{,g}vimrc{,.before,.after}"', msg='delete ~/.vimrc, ~/.vimrc.before, ~/.vimrc.after, ' '~/.gvimrc, ~/.gvimrc.before and ~/.gvimrc.after') if exists('~/.vim.old'): run('mv ~/.vim.old ~/.vim', msg='restore ~/.vim dir') for fname in ['~/.vimrc', '~/.gvimrc']: if exists(flo('{fname}.old')): run(flo('mv {fname}.old {fname}'), msg=flo('restore {fname}')) run('ls -hal ~/.*vim*', msg='\nvim config restored:') else: print_msg('janus is not installed; nothing to do (abort)') exit(1)
def init_git_repo(basedir): basedir_abs = os.path.expanduser(basedir) if os.path.isdir(flo('{basedir_abs}/.git')): print_msg('git repo already initialized (skip)') else: if not exists('{basedir_abs}/.gitignore'): install_file_legacy(path=flo('{basedir_abs}/.gitignore'), from_path='~/repos/my_presi/.gitignore') run(flo('cd {basedir} && git init')) run(flo('cd {basedir} && git add .')) run(flo('cd {basedir} && git commit -am "Initial commit"'))
def install_readme(basedir): readme_path = flo('{basedir}/README.md') if exists(readme_path): print_msg('already exists (skip)') else: presi_title = _lazy('presi_title', os.path.basename(basedir)) presi_subtitle = _lazy('presi_subtitle') presi_description = _lazy('presi_description') install_file_legacy(path=readme_path, from_path='~/repos/my_presi/README.md', presi_title=presi_title, presi_subtitle=presi_subtitle, presi_description=presi_description, basedir=basedir)
def restore_settings_and_data(site_dir): config_restored = False data_dir_restored = False if exists(flo('{site_dir}/bak/config.ini')): run(flo('cp {site_dir}/bak/config.ini {site_dir}/selfoss/config.ini'), msg='restore config.ini') config_restored = True if exists(flo('{site_dir}/bak/data')): run(flo('sudo rsync -a --owner --group --delete --force ' '{site_dir}/bak/data {site_dir}/selfoss'), msg='restore data dir') result = False if config_restored or data_dir_restored: result = True else: print_msg('nothing to restore') return result
def revealjs(basedir=None, title=None, subtitle=None, description=None, github_user=None, github_repo=None): '''Set up or update a reveals.js presentation with slides written in markdown. Several reveal.js plugins will be set up, too. More info: Demo: https://theno.github.io/revealjs_template http://lab.hakim.se/reveal-js/ https://github.com/hakimel/reveal.js plugins: https://github.com/hakimel/reveal.js/wiki/Plugins,-Tools-and-Hardware https://github.com/rajgoel/reveal.js-plugins/ https://github.com/e-gor/Reveal.js-TOC-Progress https://github.com/e-gor/Reveal.js-Title-Footer ''' basedir = basedir or query_input('Base dir of the presentation?', default='~/repos/my_presi') revealjs_repo_name = 'reveal.js' revealjs_dir = flo('{basedir}/{revealjs_repo_name}') _lazy_dict['presi_title'] = title _lazy_dict['presi_subtitle'] = subtitle _lazy_dict['presi_description'] = description _lazy_dict['github_user'] = github_user _lazy_dict['github_repo'] = github_repo question = flo("Base dir already contains a sub dir '{revealjs_repo_name}'." ' Reset (and re-download) reveal.js codebase?') if not exists(revealjs_dir) or query_yes_no(question, default='no'): run(flo('mkdir -p {basedir}')) set_up_revealjs_codebase(basedir, revealjs_repo_name) install_plugins(revealjs_dir) apply_customizations(repo_dir=revealjs_dir) if exists(revealjs_dir): install_files_in_basedir(basedir, repo_dir=revealjs_dir) init_git_repo(basedir) create_github_remote_repo(basedir) setup_npm(revealjs_dir) else: print('abort')
def nvm(): '''Install latest or update to latest version of Node Version Manager (nvm). More infos: https://github.com/creationix/nvm/blob/master/README.markdown ''' if not exists('~/.nvm/.git'): install_nvm() enable_nvm() else: upgrade_nvm() nvm_primer()
def install_markdown_slides_template(basedir): slides_path = flo('{basedir}/slides.md') if exists(slides_path): print_msg('already exists (skip)') else: presi_title = _lazy('presi_title', os.path.basename(basedir)) presi_subtitle = _lazy('presi_subtitle') cur_date = run(r'date +%F', capture=True) install_file_legacy(path=slides_path, from_path='~/repos/my_presi/slides.md', presi_title_upper=presi_title.replace('_', ' ').upper(), presi_subtitle=presi_subtitle, cur_date=cur_date)
def setup_selfoss_user(username, sitename, site_dir): if not exists(flo('{site_dir}/selfoss/config.ini')): chars = 'abcdefghijklmnopqrstuvwxyz0123456789' salt = ''.join(random.SystemRandom().choice(chars) for _ in range(150)) install_file_legacy('~/sites/SITENAME/selfoss/config.ini', SITENAME=sitename, salt=salt) run('sudo service nginx reload') run('sudo service php5-fpm restart') selfoss_username(username, sitename) selfoss_password(sitename)
def set_up_trac_plugins(sitename, site_dir, bin_dir): plugins = [] try: from config import trac_plugins_by_sitename plugins = trac_plugins_by_sitename.get(sitename, []) except ImportError: pass # ignore non-existing config entry svn_base_url = 'https://trac-hacks.org/svn' plugin_src_basedir = flo('{site_dir}/trac-plugin-src') if plugins: for plugin in plugins: print_msg(flo('### {plugin.name}\n\nInfos: {plugin.homepage}\n')) plugin_src_dir = flo('{plugin_src_basedir}/{plugin.name}') # FIXME: simplify: All Plugins provide a zip src-file # no differing handling between git and svn required here if plugin.git_instead_of_svn: # git-repo if not exists(flo('{plugin_src_dir}/.git')): run(flo('cd {plugin_src_basedir} && ' 'git clone {plugin.git_repo_url} {plugin.name}')) else: run(flo('cd {plugin_src_dir} && git pull')) else: # svn-repo if exists(plugin_src_dir): run(flo('cd {plugin_src_dir} && svn up'), msg='update plugin repo:') else: run(flo('mkdir -p {plugin_src_basedir}'), msg='checkout plugin repo:') run(flo('svn checkout ' '{svn_base_url}/{plugin.name}/{plugin.svn_version} ' ' {plugin_src_dir}')) run(flo('{bin_dir}/pip install --upgrade {plugin_src_dir}'), msg='install plugin:') else: print_msg('plugins not configured in fabsetup_custom/setup.py: ' 'nothing to do')
def custom_index_html(basedir, repo_dir): if exists(flo('{repo_dir}/index.html')): run(flo('cd {repo_dir} && cp --no-clobber index.html index.html_orig'), 'save original index.html') index_html_path = flo('{basedir}/index.html') if exists(index_html_path): print_msg('\nalready exists (skip)') else: presi_title = _lazy('presi_title', os.path.basename(basedir)) print_msg(flo('\ncustomizations of index.html:\n' " * <title>{presi_title}</title>\n" " * 'solarized' as default theme\n" " * load plugins 'menu', 'solarized', 'toc-progress'\n" " * config for plugins: 'menu', 'math'\n" "")) install_file_legacy(path=index_html_path, from_path='~/repos/my_presi/index.html', presi_title_space=presi_title.replace('_', ' ')) thanks_img_path = flo('{basedir}/img/thanks.jpg') if not exists(thanks_img_path): install_file_legacy(path=thanks_img_path, from_path='~/repos/my_presi/img/thanks.jpg')
def custom_index_html(basedir, repo_dir): if exists(flo('{repo_dir}/index.html')): run(flo('cd {repo_dir} && cp --no-clobber index.html index.html_orig'), 'save original index.html') index_html_path = flo('{basedir}/index.html') if exists(index_html_path): print_msg('\nalready exists (skip)') else: presi_title = _lazy('presi_title', os.path.basename(basedir)) print_msg( flo('\ncustomizations of index.html:\n' " * <title>{presi_title}</title>\n" " * 'solarized' as default theme\n" " * load plugins 'menu', 'solarized', 'toc-progress'\n" " * config for plugins: 'menu', 'math'\n" "")) install_file_legacy(path=index_html_path, from_path='~/repos/my_presi/index.html', presi_title_space=presi_title.replace('_', ' ')) thanks_img_path = flo('{basedir}/img/thanks.jpg') if not exists(thanks_img_path): install_file_legacy(path=thanks_img_path, from_path='~/repos/my_presi/img/thanks.jpg')
def checkout_latest_release_of_selfoss(): if not exists('~/repos/selfoss/.git'): checkup_git_repo_legacy('https://github.com/SSilence/selfoss.git') else: run('cd ~/repos/selfoss && git fetch') # TODO since selfoss-2.17 Composer is required which needs to be set up # on ubuntu 14.04: # * https://www.digitalocean.com/community/tutorials/how-to-install-and-use-composer-on-ubuntu-14-04 # * https://getcomposer.org/ # latest_tag = 'git describe --abbrev=0 --tags --match "[0-9.]*" origin' # run(flo('cd ~/repos/selfoss && git checkout $({latest_tag})')) latest_working_tag = '2.16' run(flo('cd ~/repos/selfoss && git checkout {latest_working_tag}')) run(flo('cd ~/repos/selfoss && git status')) # show latest version
def telegram(): '''Install Telegram desktop client for linux (x64). More infos: https://telegram.org https://desktop.telegram.org/ ''' if not exists('~/bin/Telegram', msg='Download and install Telegram:'): run('mkdir -p /tmp/telegram') run('cd /tmp/telegram && wget https://telegram.org/dl/desktop/linux') run('cd /tmp/telegram && tar xf linux') with warn_only(): run('mv /tmp/telegram/Telegram ~/bin') run('rm -rf /tmp/telegram') else: print('skip download, dir ~/bin/Telegram already exists') run('ln -snf ~/bin/Telegram/Telegram ~/bin/telegram', msg="\nCreate executable 'telegram':")
def pyenv(): '''Install or update the pyenv python environment. Checkout or update the pyenv repo at ~/.pyenv and enable the pyenv. Pyenv wird also als Github-Repo "installiert" unter ~/.pyenv More info: * https://github.com/yyuu/pyenv * https://github.com/yyuu/pyenv/wiki/Common-build-problems#requirements Tutorial: * http://amaral-lab.org/resources/guides/pyenv-tutorial ''' install_packages([ 'make', 'build-essential', 'libssl-dev', 'zlib1g-dev', 'libbz2-dev', 'libreadline-dev', 'libsqlite3-dev', 'wget', 'curl', 'llvm', 'libncurses5-dev', 'libncursesw5-dev', ]) if exists('~/.pyenv'): run('cd ~/.pyenv && git pull') run('~/.pyenv/bin/pyenv update') else: run('curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/' 'master/bin/pyenv-installer | bash') # add pyenv to $PATH and set up pyenv init bash_snippet = '~/.bashrc_pyenv' install_file_legacy(path=bash_snippet) prefix = flo('if [ -f {bash_snippet} ]; ') enabler = flo('if [ -f {bash_snippet} ]; then source {bash_snippet}; fi') if env.host == 'localhost': # FIXME: next function currently only works for localhost uncomment_or_update_or_append_line(filename='~/.bashrc', prefix=prefix, new_line=enabler) else: print(cyan('\nappend to ~/.bashrc:\n\n ') + enabler)
def vim_janus(uninstall=None): '''Install or update Janus, a distribution of addons and mappings for vim. More info: https://github.com/carlhuda/janus Customization: https://github.com/carlhuda/janus/wiki/Customization Args: uninstall: If not None, Uninstall janus and restore old vim config ''' if uninstall is not None: uninstall_janus() else: if not exists('~/.vim/janus'): print_msg('not installed => install') install_janus() else: print_msg('already installed => update') update_janus() customize_janus() show_files_used_by_vim_and_janus()
def create_virtualenv(site_dir): if not exists(flo('{site_dir}/virtualenv/bin/pip')): python_version = 'python2' # FIXME take latest python via pyenv run(flo('virtualenv --python={python_version} {site_dir}/virtualenv'))