Skip to content

Instantly share code, notes, and snippets.

@ArnyminerZ
Last active November 27, 2022 20:11
Show Gist options
  • Save ArnyminerZ/ceb0ae8f3f54c7772fe3ec9b2c471466 to your computer and use it in GitHub Desktop.
Save ArnyminerZ/ceb0ae8f3f54c7772fe3ec9b2c471466 to your computer and use it in GitHub Desktop.
wkhtmltopdf
import ruamel.yaml
import subprocess
fname = "config/config.yml"
config, ind, bsi = ruamel.yaml.util.load_yaml_guess_indent(open(fname))
wkhtmltopdf = subprocess.run(['which', 'wkhtmltopdf'], stdout=subprocess.PIPE)
wkhtmltopdf_path = wkhtmltopdf.stdout.decode('utf-8').replace("\"", "").replace("\n", "")
rake_secret_raw = subprocess.run(['rake', 'secret'], stdout=subprocess.PIPE)
rake_secret = rake_secret_raw.stdout.decode('utf-8').split("\n")[-2]
production = config['development']
production['wkhtmltopdf_path'] = wkhtmltopdf_path
production['encryption_key'] = rake_secret
yaml = ruamel.yaml.YAML()
yaml.indent(mapping=ind, sequence=ind, offset=bsi)
with open(fname, 'w') as fp:
yaml.dump(config, fp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment