def get_packages(): # retrieve list of installed software c = FileManager.capture_output(["reg", "query", "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", "/s"]) # parse install locations out of this packages = [] for match in re.finditer(r"InstallLocation\s*REG_SZ[ \t]*([a-zA-Z][^\n]+)\r\n", c): install_location = match.group(1) packages.append(Package(install_location)) return packages
def db_exists(dbname): '''helper to return boolean indicating if the db w/ the specified name exists''' mysql_password = snap.config.options.service_options['mysql_password'] # retrieve list of db names from mysql c = FileManager.capture_output([Mysql.MYSQL_CMD, "-e", "show databases", "-u", "root", "-p" + mysql_password]) # determine if the specified one is among them has_db = len(re.findall(dbname, c)) return has_db
def db_exists(dbname): '''helper to return boolean indicating if the db w/ the specified name exists''' # get the env containing the postgres password penv = Postgresql.set_pgpassword_env() # retrieve list of db names from postgres c = FileManager.capture_output([Postgresql.PSQL_CMD, "--username", "postgres", "-t", "-c", "select datname from pg_database"], env=penv) # determine if the specified one is among them has_db = len(re.findall(dbname, c)) return has_db
def db_exists(dbname): '''helper to return boolean indicating if the db w/ the specified name exists''' mysql_password = snap.config.options.service_options['mysql_password'] # retrieve list of db names from mysql c = FileManager.capture_output([ Mysql.MYSQL_CMD, "-e", "show databases", "-u", "root", "-p" + mysql_password ]) # determine if the specified one is among them has_db = len(re.findall(dbname, c)) return has_db
def get_packages(): # retrieve list of installed software c = FileManager.capture_output([ "reg", "query", "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", "/s" ]) # parse install locations out of this packages = [] for match in re.finditer( r"InstallLocation\s*REG_SZ[ \t]*([a-zA-Z][^\n]+)\r\n", c): install_location = match.group(1) packages.append(Package(install_location)) return packages
def db_exists(dbname): '''helper to return boolean indicating if the db w/ the specified name exists''' # get the env containing the postgres password penv = Postgresql.set_pgpassword_env() # retrieve list of db names from postgres c = FileManager.capture_output([ Postgresql.PSQL_CMD, "--username", "postgres", "-t", "-c", "select datname from pg_database" ], env=penv) # determine if the specified one is among them has_db = len(re.findall(dbname, c)) return has_db
def backup(self, basedir, include=[], exclude=[]): """backup the files modified outside the apt package system""" if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Backing up files on windows") # get list of hard drives if len(include) == 0: drives = [] c = FileManager.capture_output(["fsutil", "fsinfo", "drives"]) drives = c.split()[1:] # loop through each drive and determine which are available for drive in drives: include_drive = True try: os.listdir(drive) except WindowsError, e: include_drive = False if include_drive: include.append(drive)
def backup(self, basedir, include=[], exclude=[]): """backup the files modified outside the apt package system""" if snap.config.options.log_level_at_least('verbose'): snap.callback.snapcallback.message("Backing up files on windows") # get list of hard drives if len(include) == 0: drives = [] c = FileManager.capture_output(["fsutil", "fsinfo", "drives"]) drives = c.split()[1:] # loop through each drive and determine which are available for drive in drives: include_drive = True try: os.listdir(drive) except WindowsError, e: include_drive = False if include_drive: include.append(drive)
def testCaptureOutputWithStdout(self): out = FileManager.capture_output(['expr', '1', '/', '0']) self.assertEqual("expr: division by zero\n", out)
def testCaptureOutput(self): out = FileManager.capture_output(['echo', 'yo']) self.assertEqual("yo\n", out)
def testCaptureOutputWithStdout(self): out = FileManager.capture_output(['expr', '1', '/', '0']) self.assertEqual("expr: division by zero\n", out)
def testCaptureOutput(self): out = FileManager.capture_output(['echo', 'yo']) self.assertEqual("yo\n", out)