def load_config(self, config): log.log("Loading configuration file.") if (self.verify_file(config)): try: with open(config, 'r') as conf: options = yaml.load(conf) return options except: #todo log action return False log.log("Something went wrong! Could not open configuration file!")
def loader(self): log.log("Starting pyDBLoader test load") log.log("Loading up the configuration file!") if (self.verify_file(self.config)): log.log("Verified configuration file: " + str(self.config)) if (self.load_config(self.config)): options = self.load_config(self.config) print(options) log.log("Loaded configurations!: " + str(options)) print(options) else: log.log("Could not load configuration files. Using defaults.") else: log.log("Could not verify configuration file. Using defaults.")
def get_config(self): log.log("Getter config called!") return self.config
def verify_file(self, dbPath): log.log("Checking if ''" + dbPath + "'' is a file: " + str(os.path.isfile(dbPath))) return os.path.isfile(dbPath)
def get_dbPath(self): log.log("Getter dbPath called!") return self.dbPath
def get_dbUsername(self): log.log("Getter dbUsername called!") return self.dbUsername
def get_dbType(self): log.log("Getter dbType called!") return self.dbType
import sys import os import yaml # custom module import logging_config as log # Program starting log entry log.log("Loading up pyDBLoader...") class pyDBLoader: def __init__(self, dbType, dbPath=None, config=None, dbUsername=None, dbPassword=None, dbPort=None): self.dbType = dbType self.dbPath = dbPath self.dbUsername = dbUsername self.dbPassword = dbPassword self.config = config def get_dbType(self): log.log("Getter dbType called!") return self.dbType def get_dbPath(self): log.log("Getter dbPath called!")
#!/usr/bin/python import sqlite3, logging, logging_config, time logging_config.log() def writedb(**fields): first_name = fields['first_name'] last_name = fields['last_name'] txn_id = fields['txn_id'] receiver_email = fields['receiver_email'] payment_status = fields['payment_status'] tax = fields['tax'] residence_country = fields['residence_country'] invoice = fields['invoice'] address_state = fields['address_state'] payer_status = fields['payer_status'] txn_type = fields['txn_type'] address_street = fields['address_street'] verify_sign = fields['verify_sign'] payment_date = fields['payment_date'] item_name = fields['item_name'] address_country = fields['address_country'] custom = fields['custom'] notify_version = fields['notify_version'] address_name = fields['address_name'] for_auction = fields['for_auction'] mc_gross_1 = fields['mc_gross_1'] test_ipn = fields['test_ipn'] logging.info('mitad de funcion') item_number = fields['item_number']
def file_exists(file): log.log("Checking if file exists: " + file + "... " + os.path.exists(file)) return os.path.exists(file)
parser.add_argument('-p', '--port', help="Port for the database if necessary", type=int) parser.add_argument('-u', '--username', help="Username for the database", type=str) parser.add_argument('--password', help="Password for the database", type=str) args = parser.parse_args() # Process configuration file argument if (args.config != config_file_default): if (file_exists(args.config) == False): log.log("Setting environment variable 'config_file_default' => " + args.config) os.environ['config_file_default'] = args.config else: print("Specified log file exists! Using default: " + config_file_default) log.log("Specified log file exists! Using default: " + config_file_default) # Process log file path argument if (args.log != log_file_default): if (file_exists(args.log) == False): log.log("Setting environment variable 'log_file_default' => " + args.log) os.environ['log_file_default'] = args.log else: print("Specified log file exists! Using default: " + log_file_default)