From 9e181342a6c745d0a0d49924d694ee7a5d162fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Marqui=CC=81nez=20Ferra=CC=81ndiz?= Date: Fri, 16 Jan 2015 20:25:43 +0100 Subject: [PATCH] gae: Use python instead of sed for removing imports (fixes #25) The '-i' option is not compatible between GNU and BSD sed. --- devscripts/gae-clean-imports.py | 21 +++++++++++++++++++++ devscripts/gae-patch-youtube-dl.sh | 9 ++------- devscripts/setup-gae.sh | 1 + 3 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 devscripts/gae-clean-imports.py diff --git a/devscripts/gae-clean-imports.py b/devscripts/gae-clean-imports.py new file mode 100644 index 00000000..818a84ad --- /dev/null +++ b/devscripts/gae-clean-imports.py @@ -0,0 +1,21 @@ +from __future__ import unicode_literals + +import sys +import re +from codecs import open + +filename = sys.argv[1] + +with open(filename, 'rt', encoding='utf-8') as f: + lines = list(f.readlines()) + +# This modules are not availabe in GAE, we don't use any of the functions +# that require them +forbidden_modules = ['fcntl', 'ctypes', 'netrc', 'ctypes'] +new_lines = (re.sub( + r'import ({})'.format('|'.join(map(re.escape, forbidden_modules))), + r'()# Removed \1 import', + l) for l in lines) + +with open(filename, 'wt', encoding='utf-8') as f: + f.writelines(new_lines) diff --git a/devscripts/gae-patch-youtube-dl.sh b/devscripts/gae-patch-youtube-dl.sh index d9066425..d60ac51f 100755 --- a/devscripts/gae-patch-youtube-dl.sh +++ b/devscripts/gae-patch-youtube-dl.sh @@ -1,10 +1,5 @@ #!/bin/bash -# This modules are not availabe in GAE, we don't use any of the functions -# that required them -forbidden_cmodules="fcntl ctypes netrc ctypes" -for module in ${forbidden_cmodules}; do - for f in **/*.py *.py; do - sed -i '' "s/import ${module}/()# Removed ${module} import/g" "$f" - done +for f in **/*.py *.py; do + python "${root}/devscripts/gae-clean-imports.py" "$f" done diff --git a/devscripts/setup-gae.sh b/devscripts/setup-gae.sh index cea724e3..16d9b200 100755 --- a/devscripts/setup-gae.sh +++ b/devscripts/setup-gae.sh @@ -1,6 +1,7 @@ #!/bin/sh root=$(pwd) +export root GAE_DIR=./gae BUILD_DIR=${GAE_DIR}/build LIB_DIR=${GAE_DIR}/lib