Beispiel #1
0
    def command_changelog(self, args):
        """
        Create and update changelog
        """
        pretty_print('Generating changelog...')
        create = args and args[0] == '--create'

        if create:
            call_command('dch --create --distributor=nirvana --changelog changelog')
        else:
            call_command('dch -i --distributor=nirvana --changelog changelog')
Beispiel #2
0
    def command_build(self, args, clean=True):
        """
        Make a deb-package
        """
        self.command_debianize(args)

        pretty_print('Building a debian package...')
        call_command('debuild -uc -us')

        if clean:
            self.command_clean(args, remove_deb=False)
Beispiel #3
0
    def command_install(self, args):
        """
        Install the package in the system
        """
        self.command_build(args, clean=False)

        pretty_print('Installing the package...')
        for package_config in self.config.packages:
            call_command('sudo dpkg -i ../%s_%s_all.deb' % (
                package_config['package']['name'],
                self.version,
            ))
        self.command_clean(args)
Beispiel #4
0
    def __init__(self, port=5432, pgpath="", host="", user="", password=""):
        self.pgpath = pgpath if pgpath else ""
        self.details_file = ""
        self.force_safe_backup = False
        self.pg_dump_version = ""
        self.env = None
        self.__is_superuser = None
        self.dbs = []
        self.stdout = ""
        self.stderr = ""
        self.retcode = 0

        command = []
        if host:
            command.append("--host=%s" % host)
        if user:
            command.append("--username=%s" % user)
        command += ["--port=%d" % int(port)]
        self.cmd_psql = [os.path.join(self.pgpath, 'psql')] + command
        self.cmd_pg_dump = [os.path.join(self.pgpath, 'pg_dump')] + command
        self.cmd_pg_dumpall = [os.path.join(self.pgpath, 'pg_dumpall')] + command

        if password:
            self.env = {'PGPASSWORD': password}

        #check pg_dump version
        try:
            self.stdout, self.stderr, self.retcode = call_command(os.path.join(pgpath, 'pg_dump') + " --version")
            self.pg_dump_version = self.__parse_version__(self.stdout)
            if self.pg_dump_version < 9.3:
                self.force_safe_backup = True
                logging.warn("pg_dump version found < 9.3. Fast backup not available.")
            self.details_file += "pg_dump version used: %s\n" % (str(self.pg_dump_version))
        except:
            raise Exception('pg_dump executable not found!')
Beispiel #5
0
def get_acpi_out():
    acpi_out, success = utils.call_command(["acpi"])

    if not success or acpi_out == "":
        return None, None, success

    acpi_split = acpi_out.split(": ")[1].split(", ")

    return acpi_split[0], acpi_split[1:], success
Beispiel #6
0
def get_acpi_out():
    acpi_out, success = utils.call_command(["acpi"])

    if not success or acpi_out == "":
        return None, None, success

    acpi_split = acpi_out.split(": ")[1].split(", ")

    return acpi_split[0], acpi_split[1:], success
Beispiel #7
0
    def list_dbs(self):
        if len(self.dbs):
            return copy(self.dbs)

        psql = " ".join(self.cmd_psql)
        cmd = ["-c", "{psql} -lqt | cut -d \| -f 1".format(psql=psql)]

        logging.info("fetching database list from server...")
        self.stdout, self.stderr, self.retcode = call_command(cmd, environment=self.env, shell=True)
        if self.retcode != 0:
            raise Exception('An error has occurred while executing command [%s] (%d): %s'
                            % (str(cmd), self.retcode, self.stderr))
        dbs = self.stdout.splitlines()
        self.dbs = filter(None, [x.strip() for x in dbs])

        return copy(self.dbs)
Beispiel #8
0
    def pg_command(self, dbname, cmd, tuple_only=True):

        command = copy(self.cmd_psql)
        if tuple_only:
            command.append("-t")
        command += ["--dbname=%s" % dbname, "--command=%s" % str(cmd)]

        self.stdout, self.stderr, self.retcode = call_command(command, environment=self.env)
        #if len(self.stderr.strip()) > 0:
        #    logging.warning(self.stderr)
        if self.retcode != 0:
            raise Exception('An error has occurred while executing command [%s] (%d): %s'
                            % (str(cmd), self.retcode, self.stderr))

        if tuple_only:
            return self.stdout.strip()
        else:
            return self.stdout.strip() + "\n"
Beispiel #9
0
    def pg_file(self, dbname, file, tuple_only=True):
        #check if file is readable
        logging.info("Checking if file is readable...")
        if not os.access(file, os.R_OK):
            raise Exception("File %s is not readable, command aborted" % file)

        command = copy(self.cmd_psql)
        if tuple_only:
            command.append("-t")
        command += ["--dbname=%s" % dbname, "--file=%s" % str(file)]

        self.stdout, self.stderr, self.retcode = call_command(command, environment=self.env)
        #if len(self.stderr.strip()) > 0:
        #    logging.warning(self.stderr)
        if self.retcode != 0:
            raise Exception('An error has occurred while executing command [%s] (%d): %s'
                            % (str(command), self.retcode, self.stderr))

        if tuple_only:
            return self.stdout.strip()
        else:
            return self.stdout.strip() + "\n"
Beispiel #10
0
 def on_privmsg(self, event, irc, arguments):
     if " ".join(arguments).startswith(config.commandChar):
         utils.call_command(self, event, irc, arguments)
Beispiel #11
0
def symbol(out):
    state = out.splitlines()[1].split(" ")[0]
    if state in symbols:
        return "<icon=%s.xbm/>" % symbols[state]
    else:
        return ""

def position(out):
    split = out.splitlines()[1].split(" ")

    found = 0
    for s in split:
        if not s == "":
            if found == 2:
                return s
            else:
                found += 1

    return ""

if __name__ == "__main__":
    out, success = utils.call_command(["mpc", "-h", host, "-f", format])
    out = utils.to_ascii(out)
    if not success:
        print(error_message)
    elif len(out.splitlines()) == 1:
        print(stopped_message)
    else:
        formatted = out.splitlines()[0]
        print("%s %s (%s)" % (symbol(out), formatted, position(out)))