update arg parse, correctly setup cwd, fixed tab/sapces
This commit is contained in:
@@ -5,6 +5,7 @@ from getpass import getpass
|
||||
import configparser
|
||||
import logging
|
||||
import argparse
|
||||
import os
|
||||
|
||||
parser = argparse.ArgumentParser(description='Sync LDAP with Seafile')
|
||||
#group = parser.add_mutually_exclusive_group()
|
||||
@@ -14,11 +15,11 @@ parser = argparse.ArgumentParser(description='Sync LDAP with Seafile')
|
||||
#group2 = parser.add_mutually_exclusive_group()
|
||||
#group2.add_argument('-t', '--text', type=str, help='text to encrypt/decrypt')
|
||||
#group2.add_argument('-f', '--file', type=str, help='file to encrypt/decrypt, will create a .pynacl file when encrypting, and requires .pynacl file to decrypt')
|
||||
parser.add_argument('-v', '--verbose', type='store_true', help='increase log level to debug')
|
||||
parser.add_argument('-v', '--verbose', action='store_true', help='increase log level to debug')
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
logger = logging.getLogger(__main__)
|
||||
logger = logging.getLogger(__name__)
|
||||
logFormatter = logging.Formatter('%(asctime)s - [%(levelname)s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
|
||||
logger.setLevel(logging.INFO)
|
||||
if args.verbose:
|
||||
@@ -34,22 +35,26 @@ consoleHandler = logging.StreamHandler()
|
||||
consoleHandler.setFormatter(logFormatter)
|
||||
logger.addHandler(consoleHandler)
|
||||
|
||||
# get directory of script
|
||||
cwd = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
# import the config file
|
||||
logger.debug("Starting to read the ini config.")
|
||||
logger.debug("Using file {}/config.ini.".format(cwd))
|
||||
config = configparser.ConfigParser()
|
||||
config.read(cwd + '/config.ini')
|
||||
|
||||
serverDNS = config['LDAP SERVER']['server']
|
||||
serverPort = config['LDAP SERVER']['port']
|
||||
serverSSL = config['LDAP SERVER'].getboolean('ssl')
|
||||
logger.debug("Server: %0, Server Port: %1, Using SSL: %3".format(serverDNS, serverPort, serverSSL))
|
||||
logger.debug("Server: {}, Server Port: {}, Using SSL: {}".format(serverDNS, serverPort, serverSSL))
|
||||
|
||||
bindAccount = config['Bind Account']['username']
|
||||
bindPassword = config['Bind Account']['password']
|
||||
logger.debug("Bind Account: %0, Bind Password: <hidden>".format(bindAccount))
|
||||
logger.debug("Bind Account: {}, Bind Password: <hidden>".format(bindAccount))
|
||||
logger.debug("Finished reading the ini config.")
|
||||
|
||||
break
|
||||
exit()
|
||||
|
||||
# setup the server
|
||||
server = Server(serverDNS, port=serverPort, use_ssl=serverSSL)
|
||||
@@ -68,7 +73,6 @@ except core.exceptions.LDAPBindError as e:
|
||||
# If the LDAP bind failed for reasons such as authentication failure.
|
||||
print('LDAP Bind Failed: ', e)
|
||||
|
||||
|
||||
# sync ad users with seafile, if disabled or deleted ad user, disable in seafile
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user