parent
							
								
									67de196e8a
								
							
						
					
					
						commit
						5790ea24ca
					
				
				 7 changed files with 80 additions and 398 deletions
			
			
		| @ -1,119 +0,0 @@ | ||||
| #!/usr/bin/env python3 | ||||
| # (c) 2014 Taeyeon MORI | ||||
| 
 | ||||
| import os | ||||
| import argparse | ||||
| import subprocess | ||||
| import hashlib | ||||
| import contextlib | ||||
| import sys | ||||
| import termios | ||||
| import shutil | ||||
| 
 | ||||
| 
 | ||||
| system = lambda *a: subprocess.check_call(a) | ||||
| 
 | ||||
| 
 | ||||
| class Package: | ||||
|     def __init__(self, x): | ||||
|         self.fqn = x | ||||
|         self.repo, self.name = x.split("/") | ||||
| 
 | ||||
| 
 | ||||
| def parse_args(argv): | ||||
|     parser = argparse.ArgumentParser(prog=argv[0]) | ||||
| 
 | ||||
|     def add_option(option, default, help=None): | ||||
|         parser.add_argument(option, default=default) | ||||
| 
 | ||||
|     def add_switch(option, default=False, help=None): | ||||
|         parser.add_argument(option, default=default, action="store_const", const=not default) | ||||
| 
 | ||||
|     parser.add_argument("package", type=Package) | ||||
| 
 | ||||
|     add_option("-buildroot", "/tmp/abs-%i" % os.getuid()) | ||||
|     add_option("-makepkg", "makepkg") | ||||
|      | ||||
|     add_switch("-nobuild") | ||||
|     add_switch("-install") | ||||
|      | ||||
|     return parser.parse_args(argv[1:]) | ||||
| 
 | ||||
| 
 | ||||
| def file_sha1(name): | ||||
|     with open(name, "rb") as f: | ||||
|         hash = hashlib.sha1() | ||||
|         while True: | ||||
|             data = f.read(2048) | ||||
|             if not data: | ||||
|                 return hash.digest() | ||||
|             hash.update(data) | ||||
| 
 | ||||
| 
 | ||||
| @contextlib.contextmanager | ||||
| def rawinput(file): | ||||
|     fd = file.fileno() if hasattr(file, "fileno") else file | ||||
|     flags = save = termios.tcgetattr(fd) | ||||
|     flags[3] &= ~termios.ICANON | ||||
|     flags[6][termios.VMIN] = 1 | ||||
|     flags[6][termios.VTIME] = 0 | ||||
|     termios.tcsetattr(fd, termios.TCSADRAIN, flags) | ||||
|     yield | ||||
|     termios.tcsetattr(fd, termios.TCSADRAIN, save) | ||||
| 
 | ||||
| 
 | ||||
| def yesno(prompt): | ||||
|     ch = "" | ||||
|     while ch not in "yYnN": | ||||
|         sys.stdout.write(prompt) | ||||
|         sys.stdout.write(" [Y/N] ") | ||||
|         sys.stdout.flush() | ||||
|         with rawinput(sys.stdin): | ||||
|             ch = sys.stdin.read(1) | ||||
|         sys.stdout.write("\r") | ||||
|     sys.stdout.write("\n") | ||||
|     return ch in "yY" | ||||
| 
 | ||||
| 
 | ||||
| def main(argv): | ||||
|     args = parse_args(argv) | ||||
| 
 | ||||
|     print("===> Synchronizing ABS") | ||||
|     system("sudo", "abs", args.package.fqn) | ||||
| 
 | ||||
|     print("===> Updating build directory") | ||||
|     ABS_DIR = os.path.join("/var/abs", args.package.fqn) | ||||
|     if not os.path.exists(ABS_DIR): | ||||
|         print("=ERROR=> No such pacakge: %s" % args.package.fqn) | ||||
|         return 1 | ||||
|     REPODIR = os.path.join(args.buildroot, args.package.repo) | ||||
|     PACKDIR = os.path.join(REPODIR, args.package.name) | ||||
|     if not os.path.exists(PACKDIR): | ||||
|         os.makedirs(PACKDIR) | ||||
|     for path, dirs, files in os.walk(ABS_DIR): | ||||
|         rel_path = os.path.relpath(path, ABS_DIR) | ||||
|         dest_path = os.path.join(PACKDIR, rel_path) | ||||
|         for dir in dirs: | ||||
|             dest = os.path.join(dest_path, dir) | ||||
|             os.path.exists(dest) or os.mkdir(dest) | ||||
|         for file in files: | ||||
|             source = os.path.join(path, file) | ||||
|             dest = os.path.join(dest_path, file) | ||||
|             (not os.path.exists(dest) or (file_sha1(source) != file_sha1(dest) and yesno("=> Overwrite %s?" % os.path.join(rel_path, file)))) and shutil.copy(source, dest) | ||||
| 
 | ||||
|     yesno("=> Edit %s PKGBUILD?" % args.package.fqn) and system(os.environ.get("EDITOR", "vim"), os.path.join(PACKDIR, "PKGBUILD")) | ||||
| 
 | ||||
|     if not args.nobuild: | ||||
|         print("===> Building Package %s" % args.package.fqn) | ||||
|         os.chdir(PACKDIR) | ||||
|         if args.install: | ||||
|             system(args.makepkg, "-i") | ||||
|         else: | ||||
|             system(args.makepkg) | ||||
|      | ||||
|     return 0 | ||||
| 
 | ||||
| 
 | ||||
| if __name__ == "__main__": | ||||
|     sys.exit(main(sys.argv)) | ||||
| 
 | ||||
| @ -1,74 +0,0 @@ | ||||
| #!/usr/bin/env python3 | ||||
| # (c) 2015 Taeyeon Mori | ||||
| # A simple script to make ln -s less painful | ||||
| # | ||||
| # Because of how symbolic links work (they're just a pathname that the OS reads and follows), | ||||
| # the link target path must always be relative to the symlink's containing directory, OR | ||||
| # an absolute path altogether. Unfortunately, ln -s does not automatically solve this issue | ||||
| # which makes it painful to create a relative symlink somewhere outside the current working | ||||
| # directory (It screws up shell completion for instance) | ||||
| # This script performs the path transformation before creating the link and can therefore be | ||||
| # used without worries of creating broken symlinks because one forgot to apply the correct | ||||
| # relative adjustment to the target path | ||||
| # | ||||
| # ex: | ||||
| # $ lns -v some-file dir/some-link | ||||
| # ln -s '../some-file' 'dir/some-link' | ||||
| # $ lns -v file ../derp/link # inside a directory called 'herp' | ||||
| # ln -s '../herp/file' '../derp/link' | ||||
| 
 | ||||
| 
 | ||||
| import os | ||||
| import argparse | ||||
| 
 | ||||
| 
 | ||||
| def transport_relpath(path, old_anchor, new_anchor): | ||||
|     """ | ||||
|     :brief: Transport a relative path from one anchor to another | ||||
|     Anchors must both be absolute paths, path must be relative (to old_anchor) | ||||
|     """ | ||||
|     return os.path.relpath(os.path.normpath(os.path.join(old_anchor, path)), new_anchor) | ||||
| 
 | ||||
| 
 | ||||
| def verbose_symlink(target, dest): | ||||
|     print("ln -s '%s' '%s'" % (target, dest)) | ||||
|     return os.symlink(target, dest) | ||||
| 
 | ||||
| 
 | ||||
| def main(argv): | ||||
|     # Command line interface to make_symlink() | ||||
|     parser = argparse.ArgumentParser(prog=argv[0], | ||||
|                                      description="A 'ln -s' command that automatically translates relative target paths to be relative to the resulting symlink's containing directory when necessary.") | ||||
|     parser.add_argument("target", help="The file(s) to create symlink(s) to", nargs="+") | ||||
|     parser.add_argument("destination", help="The path of the symbolic link(s) to create") | ||||
|     parser.add_argument("-v", "--verbose", help="Print every operation", | ||||
|                         dest="symlink", const=verbose_symlink, action="store_const", default=os.symlink) | ||||
| 
 | ||||
|     args = parser.parse_args(argv[1:]) | ||||
| 
 | ||||
|     # Multiple | ||||
|     if len(args.target) > 1: | ||||
|         if not os.path.isdir(args.destination): | ||||
|             print("Destination must be an existing directory when multiple targets are passed!") | ||||
|         for target in args.target: | ||||
|             dest = os.path.join(args.destination, os.path.basename(target)) | ||||
|             args.symlink(target if os.path.isabs(target) else transport_relpath(target, os.curdir, args.destination), dest) | ||||
| 
 | ||||
|     # One | ||||
|     else: | ||||
|         target = args.target[0] | ||||
| 
 | ||||
|         dest = ldir = args.destination | ||||
|         if os.path.isdir(dest): | ||||
|             dest = os.path.join(dest, os.path.basename(target)) | ||||
|         else: | ||||
|             ldir = os.path.dirname(dest) | ||||
| 
 | ||||
|         args.symlink(target if os.path.isabs(target) else transport_relpath(target, os.curdir, ldir), dest) | ||||
| 
 | ||||
|     return 0 | ||||
| 
 | ||||
| 
 | ||||
| if __name__ == "__main__": | ||||
|     import sys | ||||
|     sys.exit(main(sys.argv)) | ||||
| @ -1,136 +0,0 @@ | ||||
| #!/usr/bin/env python3 | ||||
| 
 | ||||
| import os | ||||
| import sys | ||||
| import subprocess | ||||
| import argparse | ||||
| 
 | ||||
| def main(): | ||||
|     try: | ||||
|         return main_() | ||||
|     except SystemExit as e: | ||||
|         try: | ||||
|             return int(e.code) | ||||
|         except: | ||||
|             print(e.code) | ||||
|             return 1 | ||||
| 
 | ||||
| def kvpair(x): | ||||
|     if x == "YES": | ||||
|         return True | ||||
|     elif x == "NO": | ||||
|         return False | ||||
|     elif x == "\\YES": | ||||
|         return "YES" | ||||
|     elif x == "\\NO": | ||||
|         return "NO" | ||||
|     else: | ||||
|         return x | ||||
| 
 | ||||
| def main_(): | ||||
|     argp = argparse.ArgumentParser() | ||||
|     argp.add_argument("source", nargs="+") | ||||
|     argp.add_argument("destination") | ||||
|     argp.add_argument("-p", "--profile", choices=["aac", "m4a", "ogg", "wav", "wma"]) | ||||
|     argp.add_argument("-u", "--update", help="Only process new files", action="store_true") | ||||
|     argp.add_argument("--avconv", default="avconv") | ||||
|     argp.add_argument("-m", nargs=2, action="append", type=kvpair, default=[]) | ||||
|     argp.add_argument("-i", nargs=2, action="append", type=kvpair, default=[]) | ||||
|     argp.add_argument("-o", nargs=2, action="append", type=kvpair, default=[]) | ||||
| 
 | ||||
|     args = argp.parse_args() | ||||
| 
 | ||||
|     i_flags = dict() | ||||
|     o_flags = dict() | ||||
|     m_flags = dict() | ||||
| 
 | ||||
|     # no video | ||||
|     o_flags["vn"] = True | ||||
|     m_flags["update"] = args.update | ||||
| 
 | ||||
|     # capability checks | ||||
|     s = subprocess.check_output([args.avconv, "-codecs"], stderr=subprocess.DEVNULL) | ||||
|     if b"faac" in s: | ||||
|         aac = {"acodec": "faac"} | ||||
|     else: | ||||
|         aac = {"acodec": "aac", "strict": "experimental"} | ||||
|     if b"libvorbis" in s: | ||||
|         vorbis = {"acodec": "libvorbis"} | ||||
|     else: | ||||
|         vorbis = {"acodec": "vorbis", "strict": "experimental"} | ||||
| 
 | ||||
|     # profiles | ||||
|     m_flags["fileext"] = "raw" | ||||
| 
 | ||||
|     if args.profile == "aac": | ||||
|         m_flags["fileext"] = "aac" | ||||
|         o_flags.update(aac) | ||||
|     elif args.profile == "m4a": | ||||
|         m_flags["fileext"] = "m4a" | ||||
|         o_flags.update(aac) | ||||
|     elif args.profile == "ogg": | ||||
|         m_flags["fileext"] = "ogg" | ||||
|         o_flags.update(vorbis) | ||||
|     elif args.profile == "wav": | ||||
|         m_flags["fileext"] = "wav" | ||||
|         o_flags["acodec"] = "pcm_f32le" | ||||
|     elif args.profile == "wma": | ||||
|         m_flags["fileext"] = "wma" | ||||
|         o_flags["acodec"] = "wmav2" | ||||
|         o_flags["ac"] = 2 | ||||
| 
 | ||||
|     i_flags.update(dict(args.i)) | ||||
|     o_flags.update(dict(args.o)) | ||||
|     m_flags.update(dict(args.m)) | ||||
| 
 | ||||
|     if len(args.source) > 1: | ||||
|         run_multiple(m_flags, args.avconv, i_flags, args.source, o_flags, args.destination) | ||||
|     else: | ||||
|         run_once(m_flags, args.avconv, i_flags, args.source[0], o_flags, args.destination) | ||||
|     return 0 | ||||
| 
 | ||||
| 
 | ||||
| def make_destfile(source, m, destination): | ||||
|     if not os.path.isdir(destination): | ||||
|         return destination | ||||
|     stem, ext = os.path.splitext(source) | ||||
|     destfile = ".".join((stem, m["fileext"])) | ||||
|     return os.path.join(destination, destfile) | ||||
| 
 | ||||
| 
 | ||||
| def add_args(argv, argdict): | ||||
|     for k,v in argdict.items(): | ||||
|         argv.append("-%s" % k) | ||||
|         if v is not True: | ||||
|             argv.append(str(v)) | ||||
| 
 | ||||
| 
 | ||||
| def make_argv(m, avconv, i, source, o, destination): | ||||
|     argv = [avconv] | ||||
|     add_args(argv, i) | ||||
|     argv.append("-i") | ||||
|     argv.append(source) | ||||
|     add_args(argv, o) | ||||
|     argv.append(make_destfile(source, m, destination)) | ||||
|     return argv | ||||
| 
 | ||||
| 
 | ||||
| def run_once(m, avconv, i, source, o, destination): | ||||
|     dest = make_destfile(source, m, destination) | ||||
|     if m["update"] and os.path.exists(dest) and os.stat(dest).st_mtime >= os.stat(source).st_mtime: | ||||
|         return | ||||
|     try: | ||||
|         subprocess.check_call(make_argv(m, avconv, i, source, o, destination)) | ||||
|     except subprocess.CalledProcessError as e: | ||||
|         raise SystemExit("Worker avconv process exited with nonzero return code: %i\nCommand was: %s\nAborting." % (e.returncode, e.cmd)) | ||||
| 
 | ||||
| 
 | ||||
| def run_multiple(m, avconv, i, sources, o, destination): | ||||
|     if not os.path.isdir(destination): | ||||
|         os.mkdir(destination) | ||||
|     for source in sources: | ||||
|         run_once(m, avconv, i, source, o, destination) | ||||
| 
 | ||||
| if __name__ == "__main__": | ||||
|     main() | ||||
| 
 | ||||
| @ -1,37 +0,0 @@ | ||||
| #!/bin/sh | ||||
| # connect to the mpd httpd and open ncmpcpp | ||||
| # Requirements: vlc, mpc, ncmpcpp | ||||
| # Use MPD_HOST, MPD_PORT, MPD_HTTP_SINK, MPD_HTTP_PORT environment variables instead of arguments | ||||
| 
 | ||||
| : ${MPD_HOST:=127.0.0.1} ${MPD_PORT:=6600} | ||||
| : ${MPD_HTTP_SINK:=1} ${MPD_HTTP_PORT:=8080} | ||||
| 
 | ||||
| export MPD_HOST | ||||
| export MPD_PORT | ||||
| 
 | ||||
| # Find programs | ||||
| mpc=`which mpc 2>/dev/null` | ||||
| vlc=`which vlc 2>/dev/null` | ||||
| client=`which ncmpcpp 2>/dev/null || which ncmpc 2>/dev/null` | ||||
| 
 | ||||
| if [ -z "$mpc" ]; then | ||||
| 	echo "ERROR: mpc (MusicPlayerClient) not found on the system" | ||||
| elif [ -z "$vlc" ]; then | ||||
| 	echo "ERROR: VLC is required for local stream playback" | ||||
| elif [ -z "$client" ]; then | ||||
| 	echo "ERROR: No MPD client installed (ncmpcpp or ncmpc)" | ||||
| else | ||||
| 	# Enable Stream | ||||
| 	mpc enable $MPC_HTTP_SINK | ||||
| 
 | ||||
|     # Play Stream (have vlc on fd:3) | ||||
| 	vlc --repeat http://$MPD_HOST:$MPD_HTTP_PORT/mpd.ogg -I dummy 2>/dev/null & | ||||
| 	vlc_pid=$! | ||||
| 
 | ||||
| 	# Launch client in pty | ||||
| 	"$client" -h $MPD_HOST -p $MPD_PORT | ||||
| 
 | ||||
| 	# Stop stream playback | ||||
| 	kill $vlc_pid | ||||
| fi | ||||
| 
 | ||||
					Loading…
					
					
				
		Reference in new issue