def undeploy(): """Delete the test project""" utils.delete_file(DTF_CONFIG) utils.delete_file(DTF_LOG_FILE) utils.delete_tree(LOCAL_MODULES_DIRECTORY)
def test_download_path(self): """Do a download to a path""" rtn = self.run_cmd("client download --path ./hosts /system/etc/hosts") utils.delete_file("hosts") assert (rtn.return_code == 0)
def test_download(self): """Do an download""" rtn = self.run_cmd("client download /system/etc/hosts") utils.delete_file("hosts") assert (rtn.return_code == 0)
def test_download_local_exists(self): """Try to download a file that already exists""" utils.touch("hosts") rtn = self.run_cmd("client download /system/etc/hosts") utils.delete_file("hosts") assert (rtn.return_code == 255)
def test_existing_file(self): """Attempt to export to exisitng file""" utils.touch("test.zip") rtn = self.run_cmd("pm export test.zip") utils.delete_file("test.zip") assert (rtn.return_code == 255)
def test_axmlprinter2(): """Run test axmlprinter2 command""" data_file = testutils.DataFile("valid_android_manifest.xml") out_file = "out.xml" rtn = included.axmlprinter2(str(data_file), out_file) utils.delete_file(out_file) assert rtn == 0
def test_named(self): """Attempt to create an archive using custom name""" version_string = "android-17_XTS" zip_name = "%s.zip" % version_string rtn = self.run_cmd("archive create %s" % zip_name) assert(rtn.return_code == 0) assert(os.path.isfile(zip_name)) utils.delete_file(zip_name)
def test_real_export(self): """Perform an export""" data_file = testutils.DataFile("integration_pm_valid_zip.zip") rtn = self.run_cmd("pm install --zip %s" % str(data_file)) assert (rtn.return_code == 0) rtn = self.run_cmd("pm export test.zip") assert (rtn.return_code == 0) assert (os.path.isfile("test.zip")) utils.delete_file("test.zip")
def test_smali(): """Run test smali/baksmali command""" data_file = testutils.DataFile("hello-world.apk") stdout, stderr, rtn_bak = included.baksmali("-o out %s" % str(data_file)) stdout, stderr, rtn_smali = included.smali("-o classes.dex out") utils.delete_tree("out") utils.delete_file("classes.dex") assert rtn_bak == 0 assert rtn_smali == 0
def test_no_name(self): """Attempt create an archive using builtin name""" config = testutils.get_default_config() version_string = "android-17_XTS" zip_name = "%s.zip" % version_string config.set("Info", "version-string", version_string) self.update_config(config) rtn = self.run_cmd("archive create") assert(rtn.return_code == 0) assert(os.path.isfile(zip_name)) utils.delete_file(zip_name)
def initialize_from_tar(tar_path, is_full=False, clean_up=False): """Initialize from a remote TAR""" # Step 1 is to unpack our TAR. Let's delete what was there first. utils.delete_tree(dtfglobals.DTF_INCLUDED_DIR) __unpack_included(tar_path) # Next, we do the the auto config. If its not clean, save the config if is_full: parser = configparser.SafeConfigParser() if __do_client_section(parser) != 0: log.e(TAG, "Error building client section of config!") return -1 if __do_bindings_section(parser) != 0: log.e(TAG, "Error building bindings section of config!") return -1 if __do_config_section(parser) != 0: log.e(TAG, "Error building global section of config!") return -1 else: # Not clean means we don't want to disturb other content in the parser = dtfglobals.get_copy() if __do_bindings_section(parser) != 0: return -1 # Next, we always want to set the version. version_string = __parse_version() parser.set(dtfglobals.CONFIG_SECTION_BINDINGS, 'version', version_string) # Save out the new config. __write_globals(parser) if clean_up: utils.delete_file(tar_path) return 0
def tearDown(self): """Remove mock project""" # Remove all content and main.db utils.delete_file(DTF_DB) utils.delete_file(DTF_CONFIG) utils.delete_file(DTF_LOG_FILE) utils.delete_tree(LOCAL_MODULES_DIRECTORY) utils.delete_tree(REPORTS_DIRECTORY)
def __do_module_delete(item): """Perform the module removal""" file_path = DTF_MODULES_DIR + item.install_name if utils.delete_file(file_path) != 0: log.e(TAG, "Error removing module file! Continuing.") conn = sqlite3.connect(DTF_DB) cur = conn.cursor() # Remove the line first. sql = ('DELETE FROM modules ' "WHERE name='%s'" % item.name) cur.execute(sql) conn.commit() return 0
def purge(): """Perform database purge""" log.i(TAG, "Starting purge....") dtf_db = sqlite3.connect(DTF_DB) cur = dtf_db.cursor() # Remove Binaries sql = ('SELECT name, install_name ' 'FROM binaries') for row in cur.execute(sql): binary_name = row[0] install_name = row[1] full_path = DTF_BINARIES_DIR + install_name log.d(TAG, "Removing binary '%s'" % binary_name) if utils.delete_file(full_path) != 0: log.e(TAG, "Error removing binary file! Continuing.") # Remove Libraries sql = ('SELECT name, install_name ' 'FROM libraries') for row in cur.execute(sql): library_name = row[0] install_name = row[1] full_path = DTF_LIBRARIES_DIR + install_name log.d(TAG, "Removing library '%s'" % library_name) if utils.delete_tree(full_path) != 0: log.e(TAG, "Error removing library! Continuing.") # Remove Modules sql = ('SELECT name, install_name ' 'FROM modules') for row in cur.execute(sql): module_name = row[0] install_name = row[1] full_path = DTF_MODULES_DIR + install_name log.d(TAG, "Removing module '%s'" % module_name) if utils.delete_file(full_path) != 0: log.e(TAG, "Error removing module file! Continuing.") # Remove Packages sql = ('SELECT name, install_name ' 'FROM packages') for row in cur.execute(sql): package_name = row[0] install_name = row[1] full_path = DTF_PACKAGES_DIR + install_name log.d(TAG, "Removing package '%s'" % package_name) if utils.delete_tree(full_path) != 0: log.e(TAG, "Error removing package! Continuing.") # Drop the DB. cur.execute("DROP TABLE IF EXISTS binaries") cur.execute("DROP TABLE IF EXISTS libraries") cur.execute("DROP TABLE IF EXISTS modules") cur.execute("DROP TABLE IF EXISTS packages") dtf_db.commit() # Rebuilding if initialize_db() != 0: log.e(TAG, "Unable to re-create dtf db!") return -1 log.i(TAG, "Purge complete!") return 0