frappe/frappe — pull request #872 by saguas (2014-10-06 11:19:32+00:00)
Title: Extends export fixtures

With this work i pretend to extend the way frappe export fixtures.

Right now frappe exports everything when asked to (frappe --export_fixtures).
Sometimes this is what we want. But most of the time what we want is just to export what my app needs to be installed in another server.

If you are working with more than one app at the same time or if you has a server just for making apps then when you export your fixtures it will export everything and get installed in other server.

How to use it:

You can continue to use it like always, no need to make any changes.
But if you just want to export what your app created (Scripts, Fields or even Doctype) you can use the extension, like this:

fixtures = [
["Custom Field",{"name":["User-karma","Customer-vat_or_nif"]}],
["Custom Script",{"name":["Account-Client", "Customer-Client"], "op":"!="}],
["Customer", {"name":r"^[r|L]","flags":"i,L,M"}],
"Item Group"
]

So, to use the extension you have to write you fixtures within brackets:

["Custom Field",{"name":["User-karma","Customer-vat_or_nif"]}]

But you can mix the styles like the example.

When you are extending you must use braces:

{"name":["User-karma","Customer-vat_or_nif"]}

Inside the braces you can use as keys name and op. Key op is the operation you want to perform, like:

= or !=
["Custom Script",{"name":["Account-Client", "Customer-Client"], "op":"!="}]

Equal (=) is the default. But you must use it explicit for performance benefits. The name key is a list of names to include or exclude.
If you want you can use regular expressions to meet your needs, and you can use it with flags or without. Without flags, the code use the default that is re.I and re.U.

["Customer", {"name":r"^[r|L]","flags":"i,L,M"}]

I include one file for tests, but the test always pass. You have to see the files that are created and verify that they are as expected. It is really difficult to make tests in this case and to make it better i will have to spend must more time, because i will need to manipulate the csv file and verify if it is like expected in code. So it is more easy to verify the files and see that all run well.