PATH:
snap
/
core18
/
2999
/
usr
/
bin
#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys import os.path import json import jsonpatch import tempfile import argparse parser = argparse.ArgumentParser( description='Apply a JSON patch on a JSON file') parser.add_argument('ORIGINAL', type=argparse.FileType('r'), help='Original file') parser.add_argument('PATCH', type=argparse.FileType('r'), nargs='?', default=sys.stdin, help='Patch file (read from stdin if omitted)') parser.add_argument('--indent', type=int, default=None, help='Indent output by n spaces') parser.add_argument('-b', '--backup', action='store_true', help='Back up ORIGINAL if modifying in-place') parser.add_argument('-i', '--in-place', action='store_true', help='Modify ORIGINAL in-place instead of to stdout') parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + jsonpatch.__version__) def main(): try: patch_files() except KeyboardInterrupt: sys.exit(1) def patch_files(): """ Diffs two JSON files and prints a patch """ args = parser.parse_args() doc = json.load(args.ORIGINAL) patch = json.load(args.PATCH) result = jsonpatch.apply_patch(doc, patch) if args.in_place: dirname = os.path.abspath(os.path.dirname(args.ORIGINAL.name)) try: # Attempt to replace the file atomically. We do this by # creating a temporary file in the same directory as the # original file so we can atomically move the new file over # the original later. (This is done in the same directory # because atomic renames do not work across mount points.) fd, pathname = tempfile.mkstemp(dir=dirname) fp = os.fdopen(fd, 'w') atomic = True except OSError: # We failed to create the temporary file for an atomic # replace, so fall back to non-atomic mode by backing up # the original (if desired) and writing a new file. if args.backup: os.rename(args.ORIGINAL.name, args.ORIGINAL.name + '.orig') fp = open(args.ORIGINAL.name, 'w') atomic = False else: # Since we're not replacing the original file in-place, write # the modified JSON to stdout instead. fp = sys.stdout # By this point we have some sort of file object we can write the # modified JSON to. json.dump(result, fp, indent=args.indent) fp.write('\n') if args.in_place: # Close the new file. If we aren't replacing atomically, this # is our last step, since everything else is already in place. fp.close() if atomic: try: # Complete the atomic replace by linking the original # to a backup (if desired), fixing up the permissions # on the temporary file, and moving it into place. if args.backup: os.link(args.ORIGINAL.name, args.ORIGINAL.name + '.orig') os.chmod(pathname, os.stat(args.ORIGINAL.name).st_mode) os.rename(pathname, args.ORIGINAL.name) except OSError: # In the event we could not actually do the atomic # replace, unlink the original to move it out of the # way and finally move the temporary file into place. os.unlink(args.ORIGINAL.name) os.rename(pathname, args.ORIGINAL.name) if __name__ == "__main__": main()
[+]
..
[-] [
[edit]
[-] aa-enabled
[edit]
[-] aa-exec
[edit]
[-] addpart
[edit]
[-] apt
[edit]
[-] apt-cache
[edit]
[-] apt-get
[edit]
[-] arch
[edit]
[-] awk
[edit]
[-] b2sum
[edit]
[-] base32
[edit]
[-] base64
[edit]
[-] basename
[edit]
[-] bashbug
[edit]
[-] bootctl
[edit]
[-] busctl
[edit]
[-] c_rehash
[edit]
[-] captoinfo
[edit]
[-] catchsegv
[edit]
[-] cautious-launcher
[edit]
[-] chage
[edit]
[-] chardet3
[edit]
[-] chardetect3
[edit]
[-] chattr
[edit]
[-] chcon
[edit]
[-] chfn
[edit]
[-] chrt
[edit]
[-] chsh
[edit]
[-] cksum
[edit]
[-] clear
[edit]
[-] clear_console
[edit]
[-] cloud-id
[edit]
[-] cloud-init
[edit]
[-] cloud-init-per
[edit]
[-] cmp
[edit]
[-] comm
[edit]
[-] compose
[edit]
[-] console-conf
[edit]
[-] core-sshd-host-keygen
[edit]
[-] csplit
[edit]
[-] ctstat
[edit]
[-] cut
[edit]
[-] dbus-cleanup-sockets
[edit]
[-] dbus-daemon
[edit]
[-] dbus-monitor
[edit]
[-] dbus-run-session
[edit]
[-] dbus-send
[edit]
[-] dbus-update-activation-environment
[edit]
[-] dbus-uuidgen
[edit]
[-] deb-systemd-helper
[edit]
[-] deb-systemd-invoke
[edit]
[-] delpart
[edit]
[-] dh_bash-completion
[edit]
[-] diff
[edit]
[-] diff3
[edit]
[-] dircolors
[edit]
[-] dirname
[edit]
[-] dpkg-deb
[edit]
[-] du
[edit]
[-] ec2metadata
[edit]
[-] edit
[edit]
[-] editor
[edit]
[-] env
[edit]
[-] ex
[edit]
[-] expand
[edit]
[-] expiry
[edit]
[-] expr
[edit]
[-] factor
[edit]
[-] faillog
[edit]
[-] fallocate
[edit]
[-] finalrd
[edit]
[-] find
[edit]
[-] flock
[edit]
[-] fmt
[edit]
[-] fold
[edit]
[-] free
[edit]
[-] gdbserver
[edit]
[-] getconf
[edit]
[-] getent
[edit]
[-] getopt
[edit]
[-] gpasswd
[edit]
[-] gpgv
[edit]
[-] groups
[edit]
[-] growpart
[edit]
[-] head
[edit]
[-] helpztags
[edit]
[-] hostid
[edit]
[-] hostnamectl
[edit]
[-] i386
[edit]
[-] iconv
[edit]
[-] id
[edit]
[-] infocmp
[edit]
[-] infotocap
[edit]
[-] install
[edit]
[-] ionice
[edit]
[-] ipcmk
[edit]
[-] ipcrm
[edit]
[-] ipcs
[edit]
[-] iptables-xml
[edit]
[-] ischroot
[edit]
[-] join
[edit]
[-] jsondiff
[edit]
[-] jsonpatch
[edit]
[-] jsonpointer
[edit]
[-] jsonschema
[edit]
[-] kernel-install
[edit]
[-] last
[edit]
[-] lastb
[edit]
[-] lastlog
[edit]
[-] lcf
[edit]
[-] ldd
[edit]
[-] less
[edit]
[-] lessecho
[edit]
[-] lessfile
[edit]
[-] lesskey
[edit]
[-] lesspipe
[edit]
[-] link
[edit]
[-] linux32
[edit]
[-] linux64
[edit]
[-] lnstat
[edit]
[-] locale
[edit]
[-] locale-check
[edit]
[-] localectl
[edit]
[-] localedef
[edit]
[-] logger
[edit]
[-] logname
[edit]
[-] lsattr
[edit]
[-] lscpu
[edit]
[-] lsipc
[edit]
[-] lslocks
[edit]
[-] lslogins
[edit]
[-] lsmem
[edit]
[-] lsns
[edit]
[-] mawk
[edit]
[-] mcookie
[edit]
[-] md5sum
[edit]
[-] md5sum.textutils
[edit]
[-] mesg
[edit]
[-] miniterm
[edit]
[-] mkfifo
[edit]
[-] mksquashfs
[edit]
[-] mkswapfile
[edit]
[-] namei
[edit]
[-] nawk
[edit]
[-] newgrp
[edit]
[-] nice
[edit]
[-] nl
[edit]
[-] no-apt
[edit]
[-] nohup
[edit]
[-] nproc
[edit]
[-] nsenter
[edit]
[-] nstat
[edit]
[-] numfmt
[edit]
[-] od
[edit]
[-] openssl
[edit]
[-] pager
[edit]
[-] partx
[edit]
[-] passwd
[edit]
[-] paste
[edit]
[-] pathchk
[edit]
[-] pdb3
[edit]
[-] pdb3.6
[edit]
[-] perl
[edit]
[-] perl5.26.1
[edit]
[-] pgrep
[edit]
[-] pinky
[edit]
[-] pkill
[edit]
[-] pldd
[edit]
[-] pmap
[edit]
[-] pr
[edit]
[-] print
[edit]
[-] printenv
[edit]
[-] printf
[edit]
[-] prlimit
[edit]
[-] probert
[edit]
[-] ptx
[edit]
[-] pwdx
[edit]
[-] py3clean
[edit]
[-] py3compile
[edit]
[-] py3versions
[edit]
[-] pydoc3
[edit]
[-] pydoc3.6
[edit]
[-] pygettext3
[edit]
[-] pygettext3.6
[edit]
[-] pyjwt3
[edit]
[-] python3
[edit]
[-] python3-jsondiff
[edit]
[-] python3-jsonpatch
[edit]
[-] python3-jsonpointer
[edit]
[-] python3-jsonschema
[edit]
[-] python3.6
[edit]
[-] python3.6m
[edit]
[-] python3m
[edit]
[-] rcp
[edit]
[-] rdma
[edit]
[-] realpath
[edit]
[-] rename.ul
[edit]
[-] renice
[edit]
[-] reset
[edit]
[-] resizepart
[edit]
[-] rev
[edit]
[-] rgrep
[edit]
[-] rlogin
[edit]
[-] routef
[edit]
[-] routel
[edit]
[-] rsh
[edit]
[-] rtstat
[edit]
[-] run-mailcap
[edit]
[-] runcon
[edit]
[-] rview
[edit]
[-] savelog
[edit]
[-] scp
[edit]
[-] script
[edit]
[-] scriptreplay
[edit]
[-] sdiff
[edit]
[-] see
[edit]
[-] select-editor
[edit]
[-] sensible-browser
[edit]
[-] sensible-editor
[edit]
[-] sensible-pager
[edit]
[-] seq
[edit]
[-] setarch
[edit]
[-] setsid
[edit]
[-] setterm
[edit]
[-] sftp
[edit]
[-] sg
[edit]
[-] sha1sum
[edit]
[-] sha224sum
[edit]
[-] sha256sum
[edit]
[-] sha384sum
[edit]
[-] sha512sum
[edit]
[-] shred
[edit]
[-] shuf
[edit]
[-] skill
[edit]
[-] slabtop
[edit]
[-] slogin
[edit]
[-] snap
[edit]
[-] snapctl
[edit]
[-] snice
[edit]
[-] sort
[edit]
[-] split
[edit]
[-] ssh
[edit]
[-] ssh-add
[edit]
[-] ssh-agent
[edit]
[-] ssh-argv0
[edit]
[-] ssh-copy-id
[edit]
[-] ssh-keygen
[edit]
[-] ssh-keyscan
[edit]
[-] stat
[edit]
[-] stdbuf
[edit]
[-] sudo
[edit]
[-] sudoedit
[edit]
[-] sudoreplay
[edit]
[-] sum
[edit]
[-] systemd-analyze
[edit]
[-] systemd-cat
[edit]
[-] systemd-cgls
[edit]
[-] systemd-cgtop
[edit]
[-] systemd-delta
[edit]
[-] systemd-detect-virt
[edit]
[-] systemd-mount
[edit]
[-] systemd-path
[edit]
[-] systemd-resolve
[edit]
[-] systemd-run
[edit]
[-] systemd-socket-activate
[edit]
[-] systemd-stdio-bridge
[edit]
[-] systemd-umount
[edit]
[-] tabs
[edit]
[-] tac
[edit]
[-] tail
[edit]
[-] taskset
[edit]
[-] tee
[edit]
[-] test
[edit]
[-] tic
[edit]
[-] timedatectl
[edit]
[-] timedatectl.real
[edit]
[-] timeout
[edit]
[-] tload
[edit]
[-] toe
[edit]
[-] top
[edit]
[-] touch
[edit]
[-] tput
[edit]
[-] tr
[edit]
[-] truncate
[edit]
[-] tset
[edit]
[-] tsort
[edit]
[-] tty
[edit]
[-] tzselect
[edit]
[-] ucf
[edit]
[-] ucfq
[edit]
[-] ucfr
[edit]
[-] unexpand
[edit]
[-] uniq
[edit]
[-] unlink
[edit]
[-] unshare
[edit]
[-] unsquashfs
[edit]
[-] update-alternatives
[edit]
[-] uptime
[edit]
[-] users
[edit]
[-] utmpdump
[edit]
[-] vcs-run
[edit]
[-] vi
[edit]
[-] view
[edit]
[-] vim.tiny
[edit]
[-] vmstat
[edit]
[-] w
[edit]
[-] w.procps
[edit]
[-] wall
[edit]
[-] watch
[edit]
[-] wc
[edit]
[-] whereis
[edit]
[-] which
[edit]
[-] who
[edit]
[-] whoami
[edit]
[-] wpa_passphrase
[edit]
[-] x86_64
[edit]
[-] xargs
[edit]
[-] xdg-open
[edit]
[-] xdg-settings
[edit]
[-] xxd
[edit]
[-] yes
[edit]
[-] zdump
[edit]