Skip to content

Commit

Permalink
feat(multithreading-support): Patched frame call back specially for MFTP
Browse files Browse the repository at this point in the history
  • Loading branch information
proffapt committed Jul 22, 2023
1 parent e6cdab4 commit 87cb67d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/iitkgp_erp_login/erp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import re
import sys
import inspect
import logging
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
Expand All @@ -19,7 +21,11 @@ class ErpLoginError(Exception):
def login(headers, session, ERPCREDS=None, OTP_CHECK_INTERVAL=None, LOGGING=False, SESSION_STORAGE_FILE=None):
global sessionToken
ssoToken = None
token_file = f"{get_import_location()}/{SESSION_STORAGE_FILE}" if SESSION_STORAGE_FILE else None
if len(sys.argv) == 1 and sys.argv[0] == '-c':
caller_file = None
else:
caller_file = inspect.getframeinfo(inspect.currentframe().f_back).filename
token_file = f"{get_import_location(caller_file)}/{SESSION_STORAGE_FILE}" if SESSION_STORAGE_FILE else None
if SESSION_STORAGE_FILE:
try:
with open(token_file, "r") as file:
Expand Down
13 changes: 10 additions & 3 deletions src/iitkgp_erp_login/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@
from google.auth.transport.requests import Request
from google_auth_oauthlib.flow import InstalledAppFlow

def get_import_location():
def get_import_location(caller_file=None):
if len(sys.argv) == 1 and sys.argv[0] == '-c':
return os.getcwd()
else:
current_frame = inspect.currentframe()
while current_frame.f_back:
current_frame = current_frame.f_back
frame_file = inspect.getframeinfo(current_frame).filename
if caller_file == frame_file:
break

script_file_path = inspect.getframeinfo(current_frame).filename
script_directory_path = os.path.dirname(script_file_path)

return script_directory_path

def generate_token():
token_path = os.path.join(get_import_location(), "token.json")
credentials_path = os.path.join(get_import_location(), "credentials.json")
if len(sys.argv) == 1 and sys.argv[0] == '-c':
caller_file = None
else:
caller_file = inspect.getframeinfo(inspect.currentframe().f_back.f_back.f_back).filename
token_path = os.path.join(get_import_location(caller_file), "token.json")
credentials_path = os.path.join(get_import_location(caller_file), "credentials.json")
scopes = [f"https://www.googleapis.com/auth/gmail.readonly"]

creds = None
Expand Down

0 comments on commit 87cb67d

Please sign in to comment.