Skip to content

Commit

Permalink
gae: Use python instead of sed for removing imports (fixes #25)
Browse files Browse the repository at this point in the history
The '-i' option is not compatible between GNU and BSD sed.
  • Loading branch information
jaimeMF committed Jan 16, 2015
1 parent fd4c254 commit 9e18134
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
21 changes: 21 additions & 0 deletions devscripts/gae-clean-imports.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 2 additions & 7 deletions devscripts/gae-patch-youtube-dl.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions devscripts/setup-gae.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh

root=$(pwd)
export root
GAE_DIR=./gae
BUILD_DIR=${GAE_DIR}/build
LIB_DIR=${GAE_DIR}/lib
Expand Down

0 comments on commit 9e18134

Please sign in to comment.