Best Python code snippet using fMBT_python
generate_usage_report.py
Source:generate_usage_report.py
1import os, sys, datetime2def getConnectionCmd(uname, ip, pwd="unknown"):3 cmd = "ssh " + uname + "@" + ip4 return cmd5def getDateToday():6 today = datetime.date.today()7 date_today = str(today.year) + "_" + str(today.month) + "_" + str(today.day)8 return date_today9def getDumpFileName(dbname):10 dump_file_name = dbname + "_" + getDateToday() + ".sql"11 return dump_file_name12def getDumpCmd(database_name, additional_options):13 cmd = "mysqldump " + database_name + " > " + getDumpFileName(dbname) + " " + additional_options14 return cmd15def getRetrCmd(uname, ip, file_path):16 cmd = "scp " + uname + "@" + ip + ":" + file_path17 return cmd18def getRakeCmd(action):19 cmd = "bundle exec rake " + action20 return cmd21def getDropCmd():22 return getRakeCmd("db:drop")23def getCrteCmd():24 return getRakeCmd("db:create")25def getMigrCmd():26 return getRakeCmd("db:migrate")27def getRestCmd(pwd, dbname, file_name):28 cmd = "mysql -u root -p" + pwd + " " + dbname + " < " + file_name29 return cmd30def getTableFileName(dbname, tname):31 file_name = dbname + getDateToday() + "_" + tname + ".csv"32 return file_name33def getExpoCmd(dbname, tname):34 cmd = "SELECT * INTO OUTFILE " + "'" + getTableFileName(dbname, tname) + "'" + " ENCLOSED BY '' ESCAPED BY '' LINES TERMINATED BY '\n' FROM " + tname35 return cmd36def getCopyCmd(source, destination):37 cmd = "scp " + source + " " + destination38 return cmd39def getMdrpCmd(dbname):40 cmd = "mongo\n"41 cmd += "use " + dbname + "\n"42 cmd += "db.dropDatabase()"43 return cmd44def getMrtrCmd(dbname, cname, fname):45 cmd = "mongoimport --type csv --db " + dbname + " --collection " + cname + " --file " + fname + " --headerline"46 return cmd47def getIndxCmd(dbname, cname, fields):48 cmd = "mongo\n"49 cmd += "use " + dbname + "\n"50 cmd += "db." + cname + ".ensureIndex("51 i = 052 for field in fields:53 cmd += "{" + field + ":" + "1" + "}"54 if i != len(fields) - 1:55 cmd += ","56 i += 157 cmd += ")"58def getUnixTimeStr(year, month, day):59 t = datetime.datetime(year, month, day, 0, 0, 0, 0)60 t_str = str(t.strftime("%s"))61 return t_str62def getStartTime():63 today = datetime.date.today()64 start_time = getUnixTimeStr(today.year, today.month - 1, 1)65 return start_time66def getEndTime():67 today = datetime.date.today()68 end_time = getUnixTimeStr(today.year, today.month, 1)69 return end_time70def getRprtCmd(mdname, mtname, params):71 cmd = "rails c\n"72 cmd += mdname + "." + mtname + "("73 i = 074 for param in params:75 cmd += param76 if i != len(params) - 1:77 cmd += ", "78 i += 179 cmd += ")"80 return cmd81uname = "artkn"82ip = "10.106.231.24"83pwd = "arcelik123"84dbname = "appstore_production"85add_opts = "--ignore-table=appstore_production.zapping_usages"86file_path = "/home/artkn/" + getDumpFileName(dbname)87local_pwd = ""88local_dbname = "server_development"89dump_path = "/home/artkn/mongo_dumps"90change_table = {}91m_dbname = "statistics"92conn_cmd = getConnectionCmd(uname, ip, pwd)93dump_cmd = getDumpCmd(dbname, add_opts)94retr_cmd = getRetrCmd(uname, ip, file_path)95drop_cmd = getDropCmd()96crte_cmd = getCrteCmd()97rest_cmd = getRestCmd(local_pwd, local_dbname, getDumpFileName(dbname))98migr_cmd = getMigrCmd()99ausg_cmd = getExpoCmd(local_dbname, "application_usages")100cusg_cmd = getExpoCmd(local_dbname, "channel_usages")101ccpy_cmd = getCopyCmd(getTableFileName(local_dbname, "application_usages"), dump_path)102acpy_cmd = getCopyCmd(getTableFileName(local_dbname, "channel_usages"), uname + "@" + ip + ":" + dump_path)103#arnm_cmd = getRnmeCmd("application_usages", change_table)104#arnm_cmd = getRnmeCmd("channel_usages", change_table)105mdrp_cmd = getMdrpCmd(m_dbname)106amrt_cmd = getMrtrCmd(m_dbname, "application_usages", getTableFileName(local_dbname, "application_usages"))107cmrt_cmd = getMrtrCmd(m_dbname, "channel_usages", getTableFileName(local_dbname, "channel_usages"))108andx_cmd = getIndxCmd(m_dbname, "application_usages", ["device_id", "background"])109cndx_cmd = getIndxCmd(m_dbname, "channel_usages", ["device_id", "background"])...
dbg_testcase.py
Source:dbg_testcase.py
...6class DbgTestCase(unittest.TestCase):7 """8 TestCase subclass that loads a core dump and ELF into a local Debugger9 session as a fixture.10 You must implement getDumpFilename() as a @classmethod to specify the11 dump file to load.12 - This filename should be relative to this 'test' directory, which is the cwd for the test.13 - If this dump loads an ELF file, the elf_file_name parameter in the dump file should be14 relative to the location of the dump file.15 """16 console_printer = None17 debugger = None18 dbg_service = None19 def __init__(self, methodName='runTest'):20 super().__init__(methodName)21 @staticmethod22 def get_debug_config():23 """24 Return configuration settings to use for testing.25 """26 config = {27 'dbg.verbose': False, # Don't spam terminal with debug output.28 'dbg.colors': False, # Don't use VT100 colors on output.29 'dbg.internal.stack.frames': True, # Show all stack frames.30 }31 return config32 @classmethod33 def get_debugger(cls):34 """35 Return the initialized Debugger test fixture (with dump file loaded).36 """37 return cls.debugger38 @classmethod39 def getDumpFilename(cls):40 """41 Return the filename of the test fixture image.42 """43 raise Exception("You must implement @classmethod getDumpFilename() to specify image to load")44 @classmethod45 def setUpClass(cls):46 filename = cls.getDumpFilename()47 if filename is None or len(filename) == 0:48 # No fixture setup required.49 return50 cls.console_printer = term.NullPrinter()51 cls.console_printer.start()52 binutils.start_demangle_threads(cls.console_printer.print_q)53 (debugger, dbg_service) = dump.load_dump(filename, cls.console_printer.print_q,54 config=DbgTestCase.get_debug_config())55 cls.debugger = debugger56 cls.dbg_service = dbg_service57 # Note: We do not need to call debugger.get_cmd_lock() as this is now performed58 # automatically within load_dump() before returning a debugger to us.59 @classmethod60 def tearDownClass(cls):...
DumpController.py
Source:DumpController.py
...12 self.dbController = DbControllerFactory.getDbController()13 def generateDump(self):14 self.dbController.makeDump()15 command = self.archive_command_pattern % (16 self.getDumpFilename(),17 self.getLogsPath(),18 self.config.DUMP_FILENAME19 )20 os.system(command)21 os.remove(self.config.DUMP_FILENAME)22 def sendDump(self):23 url = self.api_url % (24 self.config.MONITORING_BOT_TOKEN,25 self.config.NOTIFICATION_CHAT_ID26 )27 command = self.curl_command_pattern % (self.getDumpFilename(), url)28 os.system(command)29 os.remove(self.getDumpFilename())30 def dump(self):31 self.generateDump()32 self.sendDump()33 def getDumpFilename(self):34 dump_filename = self.dump_filename_pattern % DateTimeController.getCurrDate()35 return self.config.LOGS_FOLDER + dump_filename36 def getLogsPath(self):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!