def __init__(self, split=True, old=True, edxproblem=True, courseinfo=True, edxvideo=True): ''' Get interface to modulestore backup. Note: This class presumes modulestore was recently loaded to mongod. Class also presumes that mongod is running on localhost:27017. ''' # FIXME: don't presume modulestore is recently loaded and running self.msdb = mng.MongoClient().modulestore # Need to handle Split and Old modulestore cases self.split = split self.old = old # Switch for updating EdxProblem and CourseInfo separately (useful for testing) self.update_EP = edxproblem self.update_CI = courseinfo self.update_EV = edxvideo # Initialize MySQL connection from config file home = os.path.expanduser('~') dbFile = home + "/.ssh/mysql_user" if not os.path.isfile(dbFile): sys.exit("MySQL user credentials not found: " + dbFile) dbuser = None dbpass = None with open(dbFile, 'r') as f: dbuser = f.readline().rstrip() dbpass = f.readline().rstrip() MySQLDB.__init__(self, db="Edx", user=dbuser, passwd=dbpass)
def __init__(self, split=True, old=True, edxproblem=True, courseinfo=True, edxvideo=True, verbose=False): ''' Get interface to modulestore backup. Note: This class presumes modulestore was recently loaded to mongod. Class also presumes that mongod is running on localhost:27017. ''' # FIXME: don't presume modulestore is recently loaded and running self.msdb = mng.MongoClient().modulestore if verbose: self.setupLogging(logging.INFO, logFile=None) else: self.setupLogging(logging.WARN, logFile=None) # Need to handle Split and Old modulestore cases self.split = split self.old = old # Switch for updating EdxProblem and CourseInfo separately (useful for testing) self.update_EP = edxproblem self.update_CI = courseinfo self.update_EV = edxvideo # Initialize MySQL connection from config file home = os.path.expanduser('~') dbFile = home + "/.ssh/mysql_user" if not os.path.isfile(dbFile): sys.exit("MySQL user credentials not found: " + dbFile) dbuser = None #@UnusedVariable dbpass = None #@UnusedVariable with open(dbFile, 'r') as f: dbuser = f.readline().rstrip() dbpass = f.readline().rstrip() MySQLDB.__init__(self, db="Edx", user=dbuser, passwd=dbpass)
def __init__(self, outdir=""): ''' Initializes table export tool with db credentials from .ssh directory. Will write outfiles to current working directory unless otherwise specified. ''' # Helper function for making required directories def ensureExists(dpath): if not os.path.exists(dpath): os.mkdir(dpath) # Configure export logging n = dt.now() logDir = os.getcwd()+'/logs/' ensureExists(logDir) logging.basicConfig(filename="logs/TableExport_%d-%d-%d_%s.log" % (n.year, n.month, n.day, n.strftime('%I:%M%p')), level=logging.INFO) # Set write directory for outfiles. self.writeDir = os.getcwd()+'/'+outdir+'/' ensureExists(self.writeDir) # Get MySQL database user credentials from .ssh directory home = os.path.expanduser("~") dbFile = home + "/.ssh/mysql_user" if not os.path.isfile(dbFile): sys.exit("MySQL user credentials not found @ %s." % dbFile) dbuser, dbpass = None, None with open(dbFile, 'r') as f: dbuser, dbpass = f.readline().rstrip(), f.readline().rstrip() # Read in table lookup from .ssh directory. tblFile = home + "/.ssh/ds_table_lookup.cfg" if not os.path.isfile(tblFile): sys.exit("Table lookup file not found @ %s." % tblFile) self.tableLookup = dict() with open(tblFile, 'r') as f: for line in f: db, tbl = line.split('.') self.tableLookup[tbl] = line # Initialize MySQL database connection MySQLDB.__init__(self, user=dbuser, passwd=dbpass) logging.info("Connected to database.")
def __init__(self): ''' Initializes extractor object with credentials from .ssh directory. Set log file directory. ''' home = expanduser("~") userFile = home + '/.ssh/qualtrics_user' tokenFile = home + '/.ssh/qualtrics_token' dbFile = home + "/.ssh/mysql_user" if os.path.isfile(userFile) == False: sys.exit("User file not found: " + userFile) if os.path.isfile(tokenFile) == False: sys.exit("Token file not found: " + tokenFile) if os.path.isfile(dbFile) == False: sys.exit("MySQL user credentials not found: " + dbFile) self.apiuser = None self.apitoken = None dbuser = None #@UnusedVariable dbpass = None #@UnusedVariable with open(userFile, 'r') as f: self.apiuser = f.readline().rstrip() with open(tokenFile, 'r') as f: self.apitoken = f.readline().rstrip() with open(dbFile, 'r') as f: dbuser = f.readline().rstrip() dbpass = f.readline().rstrip() logging.basicConfig( filename="EdxQualtricsETL_%d%d%d_%d%d.log" % (dt.datetime.today().year, dt.datetime.today().month, dt.datetime.today().day, dt.datetime.now().hour, dt.datetime.now().minute), level=logging.INFO) self.lookup = IpCountryDict() #************ MySQLDB.__init__(self, db="EdxQualtrics", user=dbuser, passwd=dbpass)
def __init__(self): ''' Initializes extractor object with credentials from .ssh directory. Set log file directory. ''' home = expanduser("~") userFile = home + '/.ssh/qualtrics_user' tokenFile = home + '/.ssh/qualtrics_token' dbFile = home + "/.ssh/mysql_user" if os.path.isfile(userFile) == False: sys.exit("User file not found: " + userFile) if os.path.isfile(tokenFile) == False: sys.exit("Token file not found: " + tokenFile) if os.path.isfile(dbFile) == False: sys.exit("MySQL user credentials not found: " + dbFile) self.apiuser = None self.apitoken = None dbuser = None dbpass = None with open(userFile, 'r') as f: self.apiuser = f.readline().rstrip() with open(tokenFile, 'r') as f: self.apitoken = f.readline().rstrip() with open(dbFile, 'r') as f: dbuser = f.readline().rstrip() dbpass = f.readline().rstrip() logging.basicConfig(filename="EdxQualtricsETL_%d%d%d_%d%d.log" % (dt.datetime.today().year, dt.datetime.today().month, dt.datetime.today().day, dt.datetime.now().hour, dt.datetime.now().minute), level=logging.INFO) self.lookup = IpCountryDict() MySQLDB.__init__(self, db="EdxQualtrics", user=dbuser, passwd=dbpass)