AIFDR/inasafe — pull request #861 by akbargumbira (2014-03-05 05:01:13+00:00)
Title: Fix map_qrc_to_file function.

# Problem
Remember unformatted main dock after running scenario? https://github.com/AIFDR/inasafe/issues/831
We 'fixed' that problem by including the resources files on the package.

# Detailed Analysis
To work on this issue, I deleted the resources folder first. After fixing this one https://github.com/akbargumbira/inasafe/commit/5e1e3301069583fa8777b2a99d2adc43b4d0bc61, I still got unformatted merged-impact report. Actually the first time I got that problem is when I was implementing impact merge tools. And because I do not know that we should not use resources from file system, I use file system resources to overcome the problem. I was suspecting that there's something wrong on this function (map_qrc_to_file), but never really looked at it.

From reading the code, this is the explanation (please @mbernasocchi to confirm):
On that function, let's say we get the match string for compiled resources on the html (i.e on the form of 'qrc:/plugins/inasafe'), then the function will check if the resource exists on resources_path (our resources folder, which will be excluded once we release it). From that fact (it is excluded), it needs to create the resources on res_copy_dir. The problem is that the resources can be inside a directory, not necessarily directly inside the res_copy_dir (e.g. bootstrap.css is inside css folder, not directly inside res_copy_dir). So instead of checking if res_copy_dir exists, we should check the parent directory of the resource file itself and create that directory as the QFile.copy() can not create its parent directory.

# Effect
Because we want to exclude the resource from InaSAFE package, it will create the resources on user file system. The case is not only for running the scenario (it will create the resources on tmp/inasafe/). If we run impact merge tools, it will create the needed resources on the output directory. Is that OK @timlinux?

All the tests on safe_qgis package are passing on this branch