Commit 86d2f8cd authored by Zeyu DONG's avatar Zeyu DONG
Browse files

add post login script support

parent daeab10f
Loading
Loading
Loading
Loading

.gitattributes

deleted100644 → 0
+0 −17
Original line number Diff line number Diff line
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs     diff=csharp

# Standard to msysgit
*.doc	 diff=astextplain
*.DOC	 diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot  diff=astextplain
*.DOT  diff=astextplain
*.pdf  diff=astextplain
*.PDF	 diff=astextplain
*.rtf	 diff=astextplain
*.RTF	 diff=astextplain
+5 −2
Original line number Diff line number Diff line
@@ -103,7 +103,10 @@ venv.bak/
# mypy
.mypy_cache/

config.json
# for debug and IED
*.lnk
*.bat
.vscode

config.json
post_login.py
+11 −13
Original line number Diff line number Diff line
@@ -3,10 +3,10 @@
import os
import sys
import logging
import importlib
import json
import re
import traceback
import socket
import requests

from time import sleep
@@ -69,16 +69,6 @@ def test_network(url):
            raise BaseHTTPError("Invalid status code {code}".format(code=test.status_code))


def check_ip():
    with socket.socket(socket.AF_INET,socket.SOCK_STREAM) as conn:
        try:
            conn.connect(('172.18.6.71', 12312))
            ip = conn.recv(128)
            logger.info("Your ip is: {ip}".format(ip=ip.decode()))
        except Exception as e:
            logger.error("Cannot get ip address: {msg}".format(msg=str(e)))


def main():
    logger.debug('Program started.')

@@ -114,7 +104,15 @@ def main():
                    logger.error('Error occurred: %s', str(err), exc_info=True)
                elif success:
                    logger.info('Login successful')
                    check_ip()
                    
                    # define the orperation after login
                    try:
                        __import__("post_login").run()
                    except ModuleNotFoundError:
                        pass
                    except Exception as e:
                        logger.error("Error in executing run() in post_login: %s",e , exc_info=True)
                    
                    return
        except RequestException as err:
            logger.warn('Network FAILED.')