Skip to content

Commit

Permalink
fix import order for logging subsystem
Browse files Browse the repository at this point in the history
  • Loading branch information
adriansev committed Nov 22, 2023
1 parent 050f321 commit 1356860
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 22 deletions.
11 changes: 5 additions & 6 deletions alienpy/alien.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ def shlex_join(split_command: list) -> str: return ' '.join(shlex.quote(arg) for
###############################################################
## IMPORT ALIENPY SUB-MODULES

## START LOGGING BEFORE ANYTHING ELSE
from .setup_logging import print_err, print_out, setup_logging, DEBUG, DEBUG_FILE
setup_logging(bool(DEBUG), DEBUG_FILE) # Initialize logging
## IMPORT VERSION STRINGS
from .version import ALIENPY_VERSION_DATE, ALIENPY_VERSION_HASH, ALIENPY_VERSION_STR
## IMPORT DATA STRUCTURES
from .data_structs import RET
## IMPORT GLOBAL VARIABLES
from .global_vars import ALIENPY_EXECUTABLE, ALIENPY_GLOBAL_WB, AlienSessionInfo, COLORS, DEBUG, DEBUG_FILE, TOKENCERT_NAME, cmds_split, lfn_prefix_re, specs_split
## START LOGGING BEFORE ANYTHING ELSE
from .setup_logging import print_err, print_out, setup_logging
from .global_vars import ALIENPY_EXECUTABLE, ALIENPY_GLOBAL_WB, AlienSessionInfo, COLORS, TOKENCERT_NAME, cmds_split, lfn_prefix_re, specs_split
## ASYNCIO MECHANICS
from .wb_api import InitConnection, SendMsg, cd, get_help_srv, retf_print, token_regen, wb_ping
## SSL RELATED VARIABLES: TOKEN AND CERT NAMES
Expand All @@ -74,9 +75,6 @@ def shlex_join(split_command: list) -> str: return ' '.join(shlex.quote(arg) for

session_id = None # variable used to keep a session ID

# Initialize logging
setup_logging(bool(DEBUG), DEBUG_FILE)

# Global XRootD preferences
xrd_config_init()

Expand Down Expand Up @@ -1898,6 +1896,7 @@ def main() -> None:
if DEBUG_ARG:
os.environ['ALIENPY_DEBUG'] = '1'
DEBUG = '1'
logging.getLogger().setLevel(logging.DEBUG)

DEBUGFILE_ARG = get_arg_value(sys.argv, '-debugfile')
if DEBUGFILE_ARG:
Expand Down
4 changes: 2 additions & 2 deletions alienpy/connect_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
sys.exit(1)

## GLOBALS
from .setup_logging import print_err, DEBUG, DEBUG_FILE
from .data_structs import CertsInfo, RET
from .global_vars import AlienSessionInfo, COLORS, DEBUG, DEBUG_FILE, TOKENCERT_NAME, TOKENKEY_NAME, USERCERT_NAME, USERKEY_NAME, USER_HOME
from .global_vars import AlienSessionInfo, COLORS, TOKENCERT_NAME, TOKENKEY_NAME, USERCERT_NAME, USERKEY_NAME, USER_HOME
from .tools_nowb import PrintColor, path_readable
from .setup_logging import print_err


def get_ca_path() -> str:
Expand Down
3 changes: 0 additions & 3 deletions alienpy/global_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ def get_certs_names() -> CertsInfo:
TIME_CONNECT = os.getenv('ALIENPY_TIMECONNECT', '')
DEBUG_TIMING = os.getenv('ALIENPY_TIMING', '') # enable really detailed timings in logs

DEBUG = os.getenv('ALIENPY_DEBUG', '')
DEBUG_FILE = os.getenv('ALIENPY_DEBUG_FILE', f'{USER_HOME}/alien_py.log')

REGEX_PATTERN_TYPE = type(re.compile('.'))
guid_regex = re.compile('[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}', re.IGNORECASE) # regex for identification of GUIDs
cmds_split = re.compile(';|\n') # regex for spliting chained commands
Expand Down
3 changes: 2 additions & 1 deletion alienpy/setup_cwd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import logging
import sys

from .global_vars import AlienSessionInfo, DEBUG
from .setup_logging import DEBUG
from .global_vars import AlienSessionInfo
from .tools_nowb import read_conf_file
from .wb_api import cd

Expand Down
2 changes: 2 additions & 0 deletions alienpy/setup_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
### ENABLE LOGGING BEFORE ANYTHIN ELSE
#############################################

DEBUG = os.getenv('ALIENPY_DEBUG', '')
DEBUG_FILE = os.getenv('ALIENPY_DEBUG_FILE', f'{USER_HOME}/alien_py.log')

def print_out(msg: str, toLog: bool = False) -> None:
"""wrapper for print/log to stdout"""
Expand Down
4 changes: 2 additions & 2 deletions alienpy/tools_nowb.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import xml.dom.minidom as MD # nosec B408:blacklist

from .data_structs import ALIEN_COLLECTION_EL, KV, RET, STAT_FILEPATH
from .global_vars import ALIENPY_FANCY_PRINT, AlienSessionInfo, COLORS, DEBUG, HAS_COLOR, REGEX_PATTERN_TYPE, TMPDIR, USER_HOME, emptyline_re, guid_regex, ignore_comments_re, lfn_prefix_re, rich_print_json
from .setup_logging import print_err, print_out
from .global_vars import ALIENPY_FANCY_PRINT, AlienSessionInfo, COLORS, HAS_COLOR, REGEX_PATTERN_TYPE, TMPDIR, USER_HOME, emptyline_re, guid_regex, ignore_comments_re, lfn_prefix_re, rich_print_json
from .setup_logging import print_err, print_out, DEBUG
from .tools_shell import is_cmd, runShellCMD


Expand Down
4 changes: 2 additions & 2 deletions alienpy/wb_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from websockets import WebSocketClientProtocol

from .data_structs import RET
from .global_vars import ALIENPY_GLOBAL_WB, AlienSessionInfo, DEBUG, DEBUG_FILE, DEBUG_TIMING, TIME_CONNECT, TMPDIR, get_certs_names
from .setup_logging import print_err, print_out
from .setup_logging import print_err, print_out, DEBUG, DEBUG_FILE
from .global_vars import ALIENPY_GLOBAL_WB, AlienSessionInfo, DEBUG_TIMING, TIME_CONNECT, TMPDIR, get_certs_names
from .async_tools import syncify
from .wb_async import IsWbConnected, wb_close, wb_create, wb_sendmsg, wb_sendmsg_multi
from .tools_nowb import CreateJsonCommand, PrintDict, deltat_ms_perf, deltat_us_perf, isReachable, is_help, is_my_pid, path_readable, read_conf_file, writePidFile
Expand Down
4 changes: 2 additions & 2 deletions alienpy/wb_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
sys.exit(1)

from .version import ALIENPY_VERSION_STR
from .global_vars import DEBUG, DEBUG_FILE, DEBUG_TIMING, TMPDIR
from .setup_logging import print_err, DEBUG, DEBUG_FILE
from .global_vars import DEBUG_TIMING, TMPDIR
from .tools_nowb import deltat_ms_perf
from .setup_logging import print_err
from .connect_ssl import create_ssl_context, renewCredFilesInfo
from .async_tools import start_asyncio, syncify

Expand Down
4 changes: 2 additions & 2 deletions alienpy/xrd_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
from typing import Union

from .version import ALIENPY_VERSION_STR
from .setup_logging import print_err, print_out, DEBUG, DEBUG_FILE
from .data_structs import CommitInfo, CopyFile, RET, XrdCpArgs, lfn2file
from .global_vars import AlienSessionInfo, COLORS, DEBUG, DEBUG_FILE, REGEX_PATTERN_TYPE, specs_split
from .setup_logging import print_err, print_out
from .global_vars import AlienSessionInfo, COLORS, REGEX_PATTERN_TYPE, specs_split
from .wb_api import SendMsg, retf_print
from .tools_nowb import (GetHumanReadableSize, PrintColor, common_path, create_metafile, deltat_ms_perf,
fileIsValid, fileline2list, format_dst_fn, get_arg, get_arg_value, get_hash_meta, get_lfn_key, get_lfn_name, get_size_meta,
Expand Down
4 changes: 2 additions & 2 deletions alienpy/xrd_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import logging

from .data_structs import CommitInfo, RET, STAT_FILEPATH, lfn2file
from .global_vars import AlienSessionInfo, COLORS, DEBUG, REGEX_PATTERN_TYPE, lfn_prefix_re, specs_split
from .setup_logging import print_err
from .setup_logging import print_err, DEBUG
from .global_vars import AlienSessionInfo, COLORS, REGEX_PATTERN_TYPE, lfn_prefix_re, specs_split
from .wb_api import SendMsg, SendMsgMulti, retf_print
from .tools_nowb import CreateJsonCommand, PrintColor, create_metafile, filter_file_prop, get_arg, get_arg_value, get_lfn_key, make_tmp_fn, valid_regex

Expand Down

0 comments on commit 1356860

Please sign in to comment.