Skip to content

Commit

Permalink
added config setting file
Browse files Browse the repository at this point in the history
  • Loading branch information
rgarade committed Dec 30, 2021
1 parent 13a3ae6 commit 67f84a3
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/


.vscode
40 changes: 40 additions & 0 deletions Inscape/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import configparser
import logging
import logging.handlers as handlers
import os
from concurrent_log_handler import ConcurrentRotatingFileHandler




initfile="config/config.ini"
configParser = configparser.ConfigParser()
configParser.read(initfile)



path = configParser.get('LOG_DETAILS', 'foldername')
if not os.path.exists(path):
os.makedirs(path)




#logger
log_file = configParser.get('LOG_DETAILS', 'filename')
# print("..........file:",log_file)
# log_file1 = os.path.abspath(path)
# print(".................................................",log_file1)
file_size = configParser.get('LOG_DETAILS', 'maxbytes')
file_size=int(file_size)
file_count = configParser.get('LOG_DETAILS', 'backupCount')
file_count=int(file_count)

logger = logging.getLogger()
if not logger.handlers:
formatter = logging.Formatter('%(asctime)s -%(lineno)d - %(levelname)s - %(message)s')
logger.setLevel(logging.DEBUG)
logHandler = ConcurrentRotatingFileHandler(log_file, maxBytes=file_size, backupCount=file_count)
logHandler.setFormatter(formatter)
logger.addHandler(logHandler)
logger.info("logger implemented")
4 changes: 2 additions & 2 deletions Inscape_backend/asgi.py → Inscape/asgi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
ASGI config for Inscape_backend project.
ASGI config for Inscape project.
It exposes the ASGI callable as a module-level variable named ``application``.
Expand All @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Inscape_backend.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Inscape.settings')

application = get_asgi_application()
13 changes: 13 additions & 0 deletions Inscape/configutils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from Inscape import *

def getProperties(section,key):
try:
options = configParser.get(section,key)
return options
except:
print("unknown section:",section,key)





23 changes: 17 additions & 6 deletions Inscape_backend/settings.py → Inscape/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Django settings for Inscape_backend project.
Django settings for Inscape project.
Generated by 'django-admin startproject' using Django 3.0.8.
Expand All @@ -11,6 +11,7 @@
"""

import os
from . import configutils as configutils

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand Down Expand Up @@ -52,7 +53,7 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'Inscape_backend.urls'
ROOT_URLCONF = 'Inscape.urls'

TEMPLATES = [
{
Expand All @@ -70,16 +71,26 @@
},
]

WSGI_APPLICATION = 'Inscape_backend.wsgi.application'
WSGI_APPLICATION = 'Inscape.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
db_name = configutils.getProperties('DATABASE','name')
db_user = configutils.getProperties('DATABASE','user')
db_password = configutils.getProperties('DATABASE','password')
db_host = configutils.getProperties('DATABASE','host')

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': f"{db_name}",
'USER': f'{db_user}',
'PASSWORD': f'{db_password}',
'HOST': f'{db_host}',
'PORT': '5432',
'DISABLE_SERVER_SIDE_CURSORS': True,
}
}

Expand Down
2 changes: 1 addition & 1 deletion Inscape_backend/urls.py → Inscape/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Inscape_backend URL Configuration
"""Inscape URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Expand Down
4 changes: 2 additions & 2 deletions Inscape_backend/wsgi.py → Inscape/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
WSGI config for Inscape_backend project.
WSGI config for Inscape project.
It exposes the WSGI callable as a module-level variable named ``application``.
Expand All @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Inscape_backend.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Inscape.settings')

application = get_wsgi_application()
Empty file removed Inscape_backend/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions config/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[DATABASE]

name= inscape
user= postgres
password= postgres
host= localhost


[LOG_DETAILS]

filename =Log/Inscape.log
maxBytes=15000000
backupCount=10
foldername= Log
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Inscape_backend.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Inscape.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down

0 comments on commit 67f84a3

Please sign in to comment.