hooks/post_gen_project.py
changeset 6 365da6d54a09
parent 2 01a55c704ea1
child 8 8ab3fffe8d36
equal deleted inserted replaced
5:d39aaf8edcf8 6:365da6d54a09
    51 # Check for var directory
    51 # Check for var directory
    52 #
    52 #
    53 
    53 
    54 VAR_DIRECTORY = os.path.join(TARGET, 'var')
    54 VAR_DIRECTORY = os.path.join(TARGET, 'var')
    55 
    55 
    56 os.chown(VAR_DIRECTORY, user_id, group_id)
    56 try:
       
    57     os.chown(VAR_DIRECTORY, user_id, group_id)
       
    58 except PermissionError:
       
    59     print("WARNING: Can't set owner ({0}:{1}) for directory {2}".format(user_id, group_id, VAR_DIRECTORY))
       
    60 
    57 for root, dirs, files in os.walk(VAR_DIRECTORY):
    61 for root, dirs, files in os.walk(VAR_DIRECTORY):
    58     for dirname in dirs:
    62     for dirname in dirs:
    59         try:
    63         try:
    60             target = os.path.join(VAR_DIRECTORY, root, dirname)
    64             target = os.path.join(VAR_DIRECTORY, root, dirname)
    61             os.chown(target, user_id, group_id)
    65             os.chown(target, user_id, group_id)
    62         except PermissionError:
    66         except PermissionError:
    63             print("WARNING: Can't set permissions for directory {0}".format(target))
    67             print("WARNING: Can't set owner ({0}:{1}) for directory {2}".format(user_id, group_id, target))
    64     for filename in files:
    68     for filename in files:
    65         try:
    69         try:
    66             target = os.path.join(VAR_DIRECTORY, root, filename)
    70             target = os.path.join(VAR_DIRECTORY, root, filename)
    67             os.chown(target, user_id, group_id)
    71             os.chown(target, user_id, group_id)
    68         except PermissionError:
    72         except PermissionError:
    69             print("WARNING: Can't set permissions for file {0}".format(target))
    73             print("WARNING: Can't set owner ({0}:{1}) for file {2}".format(user_id, group_id, target))
    70 
    74 
    71 
    75 
    72 #
    76 #
    73 # Make binary scripts executable
    77 # Make binary scripts executable
    74 #
    78 #
    79     for filename in files:
    83     for filename in files:
    80         try:
    84         try:
    81             target = os.path.join(BIN_DIRECTORY, root, filename)
    85             target = os.path.join(BIN_DIRECTORY, root, filename)
    82             os.chmod(target, 0o775)
    86             os.chmod(target, 0o775)
    83         except PermissionError:
    87         except PermissionError:
    84             print("WARNING: Can't set permissions for file {0}".format(target))
    88             print("WARNING: Can't set permissions (0775) for file {0}".format(target))
    85 
    89 
    86 
    90 
    87 print("\nYour ZEO environment is initialized.")
    91 print("\nYour ZEO environment is initialized.")
    88 print("To finalize it's creation, just type:")
    92 print("To finalize it's creation, just type:")
    89 print("- cd {{ cookiecutter.project_slug }}")
    93 print("- cd {{ cookiecutter.project_slug }}")