Update main.py

Added a read-only check and add write to existing permissions

<!---
@huboard:{"order":2144.21875}
-->