From c579162ef91ce6a0d471d7c7d06f403d84b1c0a5 Mon Sep 17 00:00:00 2001 From: Aron Griffis Date: Mon, 17 Feb 2014 14:55:55 -0500 Subject: [PATCH 1/6] Use consistent syntax for declaring functions in utils --- bin/utils | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bin/utils b/bin/utils index a8af9fb..1ebe74f 100755 --- a/bin/utils +++ b/bin/utils @@ -14,39 +14,39 @@ cleanup() { } # Buildpack Steps. -function puts-step (){ +puts-step() { echo "-----> $@" } # Buildpack Warnings. -function puts-warn (){ +puts-warn() { echo " ! $@" } # Usage: $ set-env key value -function set-env (){ +set-env() { echo "export $1=$2" >> $PROFILE_PATH } # Usage: $ set-default-env key value -function set-default-env (){ +set-default-env() { echo "export $1=\${$1:-$2}" >> $PROFILE_PATH } # Usage: $ set-default-env key value -function un-set-env (){ +un-set-env() { echo "unset $1" >> $PROFILE_PATH } # Does some serious copying. -function deep-cp (){ +deep-cp() { find -H $1 -maxdepth 1 -name '.*' -a \( -type d -o -type f -o -type l \) -exec cp -a '{}' $2 \; cp -r $1/!(tmp) $2 # echo copying $1 to $2 } # Does some serious moving. -function deep-mv (){ +deep-mv() { deep-cp $1 $2 rm -fr $1/!(tmp) @@ -54,7 +54,7 @@ function deep-mv (){ } # Does some serious deleting. -function deep-rm (){ +deep-rm() { rm -fr $1/!(tmp) find -H $1 -maxdepth 1 -name '.*' -a \( -type d -o -type f -o -type l \) -exec rm -fr '{}' \; } @@ -77,4 +77,4 @@ sub-env() { $1 ) -} \ No newline at end of file +} From 5f96190eb5ccd05b90947f9a77d7ef0881816ef8 Mon Sep 17 00:00:00 2001 From: Aron Griffis Date: Mon, 17 Feb 2014 15:28:17 -0500 Subject: [PATCH 2/6] Stop calling find for simple operations. Just use extglob. Additionally use `cp -a` consistently rather than alternating between `cp -a` and `cp -r`, and don't fail compile if the glob doesn't expand to anything. --- bin/utils | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/bin/utils b/bin/utils index 1ebe74f..19af53d 100755 --- a/bin/utils +++ b/bin/utils @@ -40,23 +40,29 @@ un-set-env() { # Does some serious copying. deep-cp() { - find -H $1 -maxdepth 1 -name '.*' -a \( -type d -o -type f -o -type l \) -exec cp -a '{}' $2 \; - cp -r $1/!(tmp) $2 - # echo copying $1 to $2 + declare source="$1" target="$2" + + mkdir -p "$target" + + # cp doesn't like being called without source params, + # so make sure they expand to something first. + # subshell to avoid surprising caller with nullglob. + ( + shopt -s nullglob + set -- "$source"/!(tmp) "$source"/.{[!.],.?}* + [[ $# == 0 ]] || cp -a "$@" "$target" + ) } # Does some serious moving. deep-mv() { - deep-cp $1 $2 - - rm -fr $1/!(tmp) - find -H $1 -maxdepth 1 -name '.*' -a \( -type d -o -type f -o -type l \) -exec rm -fr '{}' \; + deep-cp "$1" "$2" + deep-rm "$1" } # Does some serious deleting. deep-rm() { - rm -fr $1/!(tmp) - find -H $1 -maxdepth 1 -name '.*' -a \( -type d -o -type f -o -type l \) -exec rm -fr '{}' \; + rm -rf "$1"/!(tmp) "$1"/.{[!.],.?}* } From e783556e6b5ad9148b3bcc5ce57abb6d7ebc32d3 Mon Sep 17 00:00:00 2001 From: Aron Griffis Date: Wed, 19 Feb 2014 20:43:18 -0500 Subject: [PATCH 3/6] dotglob FTW. Doesn't expand . or .. but be explicit just in case. --- bin/utils | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/utils b/bin/utils index 19af53d..ac94949 100755 --- a/bin/utils +++ b/bin/utils @@ -46,10 +46,10 @@ deep-cp() { # cp doesn't like being called without source params, # so make sure they expand to something first. - # subshell to avoid surprising caller with nullglob. + # subshell to avoid surprising caller with shopts. ( - shopt -s nullglob - set -- "$source"/!(tmp) "$source"/.{[!.],.?}* + shopt -s nullglob dotglob + set -- "$source"/!(tmp|.|..) [[ $# == 0 ]] || cp -a "$@" "$target" ) } @@ -62,7 +62,11 @@ deep-mv() { # Does some serious deleting. deep-rm() { - rm -rf "$1"/!(tmp) "$1"/.{[!.],.?}* + # subshell to avoid surprising caller with shopts. + ( + shopt -s dotglob + rm -rf "$1"/!(tmp|.|..) + ) } From 5ea843458a4b008b706342b2052a83174e41f715 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Wed, 2 Apr 2014 13:37:19 -0400 Subject: [PATCH 4/6] improved collectstatic experience --- bin/steps/collectstatic | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/steps/collectstatic b/bin/steps/collectstatic index ad6fdca..41f2e91 100755 --- a/bin/steps/collectstatic +++ b/bin/steps/collectstatic @@ -10,19 +10,23 @@ MANAGE_FILE=${MANAGE_FILE:-fakepath} if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ]; then set +e + echo "-----> Preparing static assets" # Check if collectstatic is configured properly. python $MANAGE_FILE collectstatic --dry-run --noinput &> /dev/null && RUN_COLLECTSTATIC=true # Compile assets if collectstatic appears to be kosher. if [ "$RUN_COLLECTSTATIC" ]; then - echo "-----> Collecting static files" + echo " Running collectstatic..." python $MANAGE_FILE collectstatic --noinput 2>&1 | sed '/^Copying/d;/^$/d;/^ /d' | indent [ $? -ne 0 ] && { - echo " ! Error running manage.py collectstatic. More info:" + echo " ! Error running 'manage.py collectstatic'. More info:" echo " http://devcenter.heroku.com/articles/django-assets" } + else + echo " ! Error running 'manage.py collectstatic --dry-run'. More info:" + echo " http://devcenter.heroku.com/articles/django-assets" fi echo From de7c16d9421c9566b6699a28971e73b49b74bfb0 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Wed, 2 Apr 2014 14:02:18 -0400 Subject: [PATCH 5/6] handhold for collectstatic --- bin/steps/collectstatic | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/steps/collectstatic b/bin/steps/collectstatic index 41f2e91..4d3b8ab 100755 --- a/bin/steps/collectstatic +++ b/bin/steps/collectstatic @@ -25,8 +25,8 @@ if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ]; then echo " http://devcenter.heroku.com/articles/django-assets" } else - echo " ! Error running 'manage.py collectstatic --dry-run'. More info:" - echo " http://devcenter.heroku.com/articles/django-assets" + echo " ! Collectstatic configuration error. To debug, run:" + echo " $ heroku run python $MANAGE_FILE collectstatic --noinput" fi echo From 8be04ea656bd037599f90722f838b714016890d3 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Wed, 2 Apr 2014 14:05:09 -0400 Subject: [PATCH 6/6] no ! --- bin/steps/collectstatic | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/steps/collectstatic b/bin/steps/collectstatic index 4d3b8ab..0821fd2 100755 --- a/bin/steps/collectstatic +++ b/bin/steps/collectstatic @@ -25,7 +25,7 @@ if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ]; then echo " http://devcenter.heroku.com/articles/django-assets" } else - echo " ! Collectstatic configuration error. To debug, run:" + echo " Collectstatic configuration error. To debug, run:" echo " $ heroku run python $MANAGE_FILE collectstatic --noinput" fi