Skip to content

Commit

Permalink
Bumped version, fixed minor typos
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbean-bremen committed Feb 15, 2017
1 parent 88015a3 commit 5440feb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 42 deletions.
2 changes: 1 addition & 1 deletion django_windows_tools/__init__.py
Expand Up @@ -6,7 +6,7 @@
__version_info__ = {
'major': 0,
'minor': 1,
'micro': 3,
'micro': 4,
'releaselevel': 'final',
'serial': 1
}
Expand Down
8 changes: 4 additions & 4 deletions django_windows_tools/management/commands/winfcgi_install.py
Expand Up @@ -125,21 +125,21 @@ class Command(BaseCommand):
action='store_true',
dest='skip_fastcgi',
default=False,
help='Skips The FastCGI application installation'),
help='Skips the FastCGI application installation'),
make_option('--skip-site',
action='store_true',
dest='skip_site',
default=False,
help='Skips The site creation'),
help='Skips the site creation'),
make_option('--skip-config',
action='store_true',
dest='skip_config',
default=False,
help='Skips The configuration creation'),
help='Skips the configuration creation'),
make_option('--log-dir',
dest='log_dir',
default='',
help='Directory for IIS logfiles (defaults to %SystemDrive%\inetpub\logs\LogFiles)'),
help=r'Directory for IIS logfiles (defaults to %SystemDrive%\inetpub\logs\LogFiles)'),
)

def __init__(self, *args, **kwargs):
Expand Down
71 changes: 34 additions & 37 deletions django_windows_tools/management/commands/winservice_install.py
Expand Up @@ -28,6 +28,7 @@
#

from __future__ import print_function

__author__ = 'Antoine Martin <antoine@openance.com>'

import os
Expand All @@ -46,29 +47,28 @@
import subprocess



def set_file_readable(filename):
import win32api
import win32security
import ntsecuritycon as con

users = win32security.ConvertStringSidToSid("S-1-5-32-545")
admins = win32security.ConvertStringSidToSid("S-1-5-32-544")
user, domain, type = win32security.LookupAccountName ("", win32api.GetUserName ())
user, domain, type = win32security.LookupAccountName("", win32api.GetUserName())

sd = win32security.GetFileSecurity (filename, win32security.DACL_SECURITY_INFORMATION)
sd = win32security.GetFileSecurity(filename, win32security.DACL_SECURITY_INFORMATION)

dacl = win32security.ACL()
dacl.AddAccessAllowedAce(win32security.ACL_REVISION, con.FILE_ALL_ACCESS, users)
dacl.AddAccessAllowedAce(win32security.ACL_REVISION, con.FILE_ALL_ACCESS, user)
dacl.AddAccessAllowedAce(win32security.ACL_REVISION, con.FILE_ALL_ACCESS, admins)
sd.SetSecurityDescriptorDacl(1, dacl, 0)
win32security.SetFileSecurity(filename, win32security.DACL_SECURITY_INFORMATION, sd)

dacl = win32security.ACL ()
dacl.AddAccessAllowedAce (win32security.ACL_REVISION, con.FILE_ALL_ACCESS, users)
dacl.AddAccessAllowedAce (win32security.ACL_REVISION, con.FILE_ALL_ACCESS, user)
dacl.AddAccessAllowedAce (win32security.ACL_REVISION, con.FILE_ALL_ACCESS, admins)
sd.SetSecurityDescriptorDacl (1, dacl, 0)
win32security.SetFileSecurity (filename, win32security.DACL_SECURITY_INFORMATION, sd)


class Command(BaseCommand):
args = ''
help = '''Creates a NT Service that runs Django commands.
help = '''Creates an NT Service that runs Django commands.
This command creates a service.py script and a service.ini
configuration file at the same level that the manage.py command.
Expand All @@ -88,7 +88,7 @@ class Command(BaseCommand):
C:\project> python service.py stop
C:\project> python service.py remove
'''

def add_arguments(self, parser):
parser.add_argument(
'--service-name',
Expand All @@ -98,7 +98,7 @@ def add_arguments(self, parser):
parser.add_argument(
'--display-name',
dest='display_name',
default='Django %s backround service',
default='Django %s background service',
help='Display name of the service')
parser.add_argument(
'--service-script-name',
Expand All @@ -113,8 +113,8 @@ def add_arguments(self, parser):
parser.add_argument(
'--log-directory',
dest='log_directory',
default='d:\logs',
help='Location for log files (d:\logs by default)')
default=r'd:\logs',
help=r'Location for log files (d:\logs by default)')
parser.add_argument(
'--beat-machine',
dest='beat_machine',
Expand All @@ -138,8 +138,7 @@ def __init__(self, *args, **kwargs):
self.current_script = os.path.abspath(sys.argv[0])
self.project_dir, self.script_name = os.path.split(self.current_script)
self.project_name = os.path.split(self.project_dir)[1]



def install_template(self, template, filename, overwrite=False, **kwargs):
full_path = os.path.join(self.project_dir, filename)
if os.path.exists(full_path) and not overwrite:
Expand All @@ -148,50 +147,48 @@ def install_template(self, template, filename, overwrite=False, **kwargs):
template = get_template(template)
file = open(full_path, 'w')
file.write(template.render(Context(kwargs)))
file.close()
file.close()
set_file_readable(full_path)

def handle(self, *args, **options):
if self.script_name == 'django-admin.py':
raise CommandError("""\
This command does not work when used with django-admin.py.
Please run it with the manage.py of the root directory of your project.
""")

if "%s" in options['service_name']:
options['service_name'] = options['service_name'] % self.project_name
options['service_name'] = options['service_name'] % self.project_name

if "%s" in options['display_name']:
options['display_name'] = options['display_name'] % self.project_name
options['display_name'] = options['display_name'] % self.project_name

self.install_template(
'windows_tools/service/service.py',
options['service_script_name'],
options['overwrite'],
service_name = options['service_name'],
display_name = options['display_name'],
config_file_name = options['config_file_name'],
settings_module = os.environ['DJANGO_SETTINGS_MODULE'],
service_name=options['service_name'],
display_name=options['display_name'],
config_file_name=options['config_file_name'],
settings_module=os.environ['DJANGO_SETTINGS_MODULE'],
)

if options['is_beat']:
options['beat_machine'] = platform.node()

if options['log_directory'][-1:] == '\\':
options['log_directory'] = options['log_directory'][0:-1]

self.install_template(
'windows_tools/service/service.ini',
options['config_file_name'],
options['overwrite'],
log_directory = options['log_directory'],
beat_machine = options['beat_machine'],
config_file_name = options['config_file_name'],
settings_module = os.environ['DJANGO_SETTINGS_MODULE'],
log_directory=options['log_directory'],
beat_machine=options['beat_machine'],
config_file_name=options['config_file_name'],
settings_module=os.environ['DJANGO_SETTINGS_MODULE'],
)




if __name__ == '__main__':
print('This is supposed to be run as a django management command')

0 comments on commit 5440feb

Please sign in to comment.