Run this stored proc from the database. It will create the SQL statements required to re-assign permissions to users defined in the database. This script will work for SQL2005 and above. There are a number of scripts out there to do this for SQL2000, and whilst these still work for SQL2005 and above they can create problems when run back in as old style syntax is used and schemas are not accounted for.
The stored proc is most useful for storing away current permissions in a database before it is overwritten by a restore from a different database, especially prod to test refreshes. After the restore you can then use the script output by the proc to recreate the permissons for the dev users. I would scan the output first and run it in sections to recreate just the permissions you need rather than just execute the whole script. With the aid of exec sp_helpuser you will need to decide for yourself what to do about users carried across from the other environment!
The stored proc can also be used to document permissions for auditing or perhaps DR purposes.
With so many types of principals and securables now there may be some edge cases not covered but this should cover 99% of cases and certainly fulfills my needs. For application roles I have used a placeholder of 'insertpwdhere' for the password as it must be specified in freetext when creating an application role and it would be a security risk to display that, and anyway there does not seem to be a way to reverse engineer the password.