changeset 403:83e1acf38d35 prerelease

Updated build_pd_heavy to support the release flag
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 15 Jun 2016 02:37:34 +0100
parents c29f07b7350e
children e72853aecab8
files scripts/build_pd_heavy.sh scripts/hvresources/uploader.py
diffstat 2 files changed, 44 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/build_pd_heavy.sh	Wed Jun 15 02:21:13 2016 +0100
+++ b/scripts/build_pd_heavy.sh	Wed Jun 15 02:37:34 2016 +0100
@@ -17,7 +17,7 @@
 #make sure the paths have the trailing / . 
 projectpath="../projects/heavy/hvtemp/"
 [ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2"
-[ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="~/BeagleRT/"
+[ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="~/Bela/"
 [ -z "$BBB_PROJECT_HOME" ] && BBB_PROJECT_HOME="${BBB_BELA_HOME}/projects/"
 BBB_DEFAULT_PROJECT_NAME="heavyProject"
 [ -z "$BBB_PROJECT_NAME" ] && BBB_PROJECT_NAME=$BBB_DEFAULT_PROJECT_NAME
@@ -39,7 +39,7 @@
 
 if [ -z "$BELA_PYTHON27" ]; then
     echo "It looks like you might not have python2.7 installed. If you do, please specify the path
-    to your python2.7 executable in the environmental variable $BELA_PYTHON27"
+    to your python2.7 executable in the environmental variable \$BELA_PYTHON27"
     exit 1;
 fi;
 
@@ -48,13 +48,15 @@
 {
 printf "\nUSAGE: build_pd.sh [[-i input folder containing _main.pd file ]\
  [-o output folder for new heavy project .c files (default ../projects/heavy/hvtemp)]\
- [-b bbb path to copy to (default ~/BeagleRT)] | [-h] | [-f|--force] | [-w|--watch] | [-n|--noupload] \n"
+ [-b bbb path to copy to (default ~/Bela)] | [-h] | [-w|--watch] | [-n|--noupload] | [-r|--release arg]\n"
 printf "\nexample: build_pd.sh -i ../projects/heavy/pd/hello-world -o ../projects/heavy/hello-world\n"
 echo "If --watch is selected, the script will check every 1s for any file that is modified in the source folder, which triggers\
 the building process and runs the process.
-If --screen is selected, the prompt returns to the user after launching BeagleRT in a screen on the target device.
+If --screen is selected, the prompt returns to the user after launching Bela in a screen on the target device.
 If --screen and --watch are combined, while the process is running in the screen, modifications to the source files will \
-still trigger a new build."
+still trigger a new build.
+-r allows to build against a specific Heavy release. Default is the most recent version.
+"
 }
 
 while [ "$1" != "" ]; do
@@ -62,14 +64,15 @@
         -b | --bbb )            shift
                                 BBB_BELA_HOME=$1
                                 ;;
-        -f | --force)           FORCE="1"
-                                ;;
         -i | --input )          shift
                                 pdpath=$1
                                 ;;
         -o | --output )         shift
                                 projectpath=$1
                                 ;;
+        -r | --release )        shift
+                                release=$1
+                                ;;
         -v | --verbose )        verbose=1
                                 ;;
         -r | --render )         shift
@@ -90,49 +93,21 @@
     shift
 done
 
-function hasNotChanged(){
-    if [ $WATCH -eq 0 ];
-    then
-        echo "Files in the source folder did not change since the last build, use --force to force recompiling";
-        exit 0;
-    fi;
-}
+if [ -z $release ]
+then 
+  RELEASE_STRING=
+else 
+  RELEASE_STRING="-r $release"
+fi
 
-function checkChanged(){
-    PD_BACKUP_PATH="hvresources/patch_back/"
-    if [ $FORCE -eq 1 ] && [ $WATCH -eq 0 ];
-    then
-        rm -rf $PD_BACKUP_PATH;
-        return;
-    fi;
-    mkdir -p $PD_BACKUP_PATH;
-    # count files that have changed
-    HAS_CHANGED=$(rsync -nac --out-format="%f" "$pdpath" $PD_BACKUP_PATH | grep -v "\/\.$"| wc -l);
-    if [ $HAS_CHANGED -eq 0 ] && [ $FORCE -eq 0 ];
-    then
-        hasNotChanged;
-        return 1;
-    fi;
-     #if we are here and $FORCE==1, it means that $WATCH==1
-     # so let's make sure only the first run get forced:
-    FORCE=0;
-    echo "Files have changed"
-    # otherwise back up the files that have changed
-    rsync -vac "$pdpath" $PD_BACKUP_PATH
-
-    return 0;
-}
-
-function checkUploadBuildRun(){
-    checkChanged || return # exits if source files have not changed
-
+function uploadBuildRun(){
     if [ $NO_UPLOAD -eq 0 ]; then
         # remove old static files to avoid obsolete errors
         # use -rf to prevent warnings in case they do not exist
         rm -rf "$projectpath"/Hv* "$projectpath"/Message* "$projectpath"/Control* "$projectpath"/Signal* &>/dev/null
 
         # invoke the online compiler
-        "$BELA_PYTHON27" hvresources/uploader.py "$pdpath"/ -n bbb -g c -o "$projectpath";
+        "$BELA_PYTHON27" hvresources/uploader.py "$pdpath"/ -n bbb -g c -o "$projectpath" $RELEASE_STRING;
         if [ $? -ne 0 ]; then
         #echo "ERROR: an error occurred while executing the uploader.py script"
         echo "error"
@@ -162,9 +137,7 @@
 
     echo "updating files on board..."
 
-    echo rsync -c -rv --exclude 'HvContext*' "$projectpath"/ "$BBB_NETWORK_TARGET_FOLDER";
     rsync -c -rv --exclude 'HvContext*' "$projectpath"/ "$BBB_NETWORK_TARGET_FOLDER";
-    # rsync -c -rv "$projectpath"/ "$BBB_ADDRESS":"$BBB_BELA_HOME"/source;
     if [ $NO_UPLOAD -eq 0 ]; then
         # for whatever reason these big files used to hang when transferring with rsync
         scp "$projectpath"/HvContext* $BBB_NETWORK_TARGET_FOLDER
@@ -186,8 +159,8 @@
     if [ $NO_UPLOAD -eq 0 ]; then
         ssh $BBB_ADDRESS "rm -rf "$BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME;
     fi;
-    SCREEN_NAME=BeagleRT
-    # Make new BeagleRT execut/able and run
+    SCREEN_NAME=Bela
+    # Make new Bela execut/able and run
     # It does not look very nice that we type the same things over and over
     # but that is because each line is an ssh session in its own right
     MAKE_COMMAND="make stop -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS'"
@@ -209,9 +182,9 @@
             ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreen"
         fi
     fi
-} #checkUploadBuildRun
+} #uploadBuildRun
 
-checkUploadBuildRun
+uploadBuildRun
 
 if [ $WATCH -ne 0 ]; then
     WAIT_STRING="\rWaiting for changes in $pdpath"
@@ -224,7 +197,7 @@
         sleep 0.3
         printf "$WAIT_STRING..."
         sleep 0.3
-        checkUploadBuildRun
+        uploadBuildRun
     done;
 fi;
 #ssh -t root@192.168.7.2 "kill -s 2 \`pidof heavy_template\` 2>/dev/null; sleep 0.5; rm -f ~/$filename_bbb/Release/source/heavy/HvContext_bbb.? ~/$filename_bbb/Release/heavy_template && make all -C ~/$filename_bbb/Release" &>/dev/null
--- a/scripts/hvresources/uploader.py	Wed Jun 15 02:21:13 2016 +0100
+++ b/scripts/hvresources/uploader.py	Wed Jun 15 02:37:34 2016 +0100
@@ -24,14 +24,19 @@
     underline = "\033[4m"
     end = "\033[0m"
 
+# the maxmimum file upload size of 1MB
+__HV_MAX_UPLOAD_SIZE = 1024*1024
+
 def __zip_dir(in_dir, zip_path, file_filter=None):
+    """Recursively zip an entire directory with an optional file filter
+    """
     zf = zipfile.ZipFile(zip_path, mode="w", compression=zipfile.ZIP_DEFLATED)
     for subdir, dirs, files in os.walk(in_dir):
-        for file in files:
-            if (file_filter is None) or (len(file_filter) > 0 and file.lower().split(".")[-1] in file_filter):
+        for f in files:
+            if (file_filter is None) or (f.lower().split(".")[-1] in file_filter):
                 zf.write(
-                    filename=os.path.join(subdir,file),
-                    arcname=os.path.relpath(os.path.join(subdir,file), start=in_dir))
+                    filename=os.path.join(subdir,f),
+                    arcname=os.path.relpath(os.path.join(subdir,f), start=in_dir))
     return zip_path
 
 def __unzip(zip_path, target_dir):
@@ -72,6 +77,9 @@
         default=["./"], # by default
         help="List of destination directories for retrieved files. Order should be the same as for --gen.")
     parser.add_argument(
+        "-r", "--release",
+        help="Optionally request a specific release of Heavy to use while compiling.")
+    parser.add_argument(
         "-d", "--domain",
         default="https://enzienaudio.com",
         help="Domain. Default is https://enzienaudio.com.")
@@ -120,6 +128,10 @@
 
     tick = time.time()
 
+    # parse the optional release argument
+    if args.release:
+        post_data["release"] = args.release
+
     # make a temporary directory
     temp_dir = tempfile.mkdtemp(prefix="lroyal-")
 
@@ -131,8 +143,11 @@
             args.input_dir,
             os.path.join(temp_dir, "archive.zip"),
             file_filter={"pd"})
+        if os.stat(zip_path).st_size > __HV_MAX_UPLOAD_SIZE:
+            raise Exception("The target directory, zipped, is {0} bytes. The maximum upload size of 1MB.".format(
+                os.stat(zip_path).st_size))
     except Exception as e:
-        print e
+        print "{0}Error:{1} {2}".format(Colours.red, Colours.end, e)
         shutil.rmtree(temp_dir) # clean up the temporary directory
         return
 
@@ -146,7 +161,7 @@
         "wwise", "wwise-win-x86_64",
         "vst2", "vst2-osx", "vst2-win-x86_64",
     }
-    post_data["gen"] = list(({"c"} | set(args.gen)) & __SUPPORTED_GENERATOR_SET)
+    post_data["gen"] = list(({"c"} | {s.lower() for s in set(args.gen)}) & __SUPPORTED_GENERATOR_SET)
 
     # upload the job, get the response back
     # NOTE(mhroth): multipart-encoded file can only be sent as a flat dictionary,