Esempio n. 1
0
    def test_pos(self):
        if not iscommand("msgfmt"):
            return

        self.failIf(os.system("msgfmt -c po/%s.po > /dev/null" % self.lang))
        try:
            os.unlink("messages.mo")
        except OSError:
            pass
Esempio n. 2
0
    def test_pos(self):
        if not iscommand("msgfmt"):
            return

        self.failIf(os.system("msgfmt -c po/%s.po > /dev/null" % self.lang))
        try:
            os.unlink("messages.mo")
        except OSError:
            pass
Esempio n. 3
0
    def test_pos(self):
        if not iscommand("msgfmt"):
            return

        po_path = os.path.join(PODIR, "%s.po" % self.lang)
        self.failIf(os.system("msgfmt -c %s > /dev/null" % po_path))
        try:
            os.unlink("messages.mo")
        except OSError:
            pass
Esempio n. 4
0
    def test_pos(self):
        if not iscommand("msgfmt"):
            return

        po_path = os.path.join(PODIR, "%s.po" % self.lang)
        self.failIf(os.system("msgfmt -c %s > /dev/null" % po_path))
        try:
            os.unlink("messages.mo")
        except OSError:
            pass
Esempio n. 5
0
 def test_looks_in_path(self):
     path_dirs = set(os.environ['PATH'].split(os.path.pathsep))
     dirs = path_dirs - set(os.defpath.split(os.path.pathsep))
     for d in dirs:
         if os.path.isdir(d):
             for file_path in os.listdir(d):
                 if os.access(os.path.join(d, file_path), os.X_OK):
                     print_d("Testing %s" % file_path)
                     self.failUnless(iscommand(file_path))
                     return
Esempio n. 6
0
 def test_looks_in_path(self):
     path_dirs = set(os.environ['PATH'].split(os.path.pathsep))
     dirs = path_dirs - set(os.defpath.split(os.path.pathsep))
     for d in dirs:
         if os.path.isdir(d):
             for file_path in os.listdir(d):
                 if os.access(os.path.join(d, file_path), os.X_OK):
                     print_d("Testing %s" % file_path)
                     self.failUnless(iscommand(file_path))
                     return
Esempio n. 7
0
 def test_looks_in_path(self):
     path_dirs = set(environ['PATH'].split(os.path.pathsep))
     dirs = path_dirs - set(os.defpath.split(os.path.pathsep))
     for d in dirs:
         if os.path.isdir(d):
             for file_path in sorted(os.listdir(d)):
                 p = os.path.join(d, file_path)
                 if os.path.isfile(p) and os.access(p, os.X_OK):
                     print_d("Testing %s" % p)
                     self.failUnless(iscommand(p), msg=p)
                     return
Esempio n. 8
0
 def test_looks_in_path(self):
     path_dirs = set(environ['PATH'].split(os.path.pathsep))
     dirs = path_dirs - set(os.defpath.split(os.path.pathsep))
     for d in dirs:
         if os.path.isdir(d):
             for file_path in sorted(os.listdir(d)):
                 p = os.path.join(d, file_path)
                 if os.path.isfile(p) and os.access(p, os.X_OK):
                     print_d("Testing %s" % p)
                     self.failUnless(iscommand(p), msg=p)
                     return
Esempio n. 9
0
def website(site):
    """Open the given URL in the user's default browser"""

    if os.name == "nt" or sys.platform == "darwin":
        return webbrowser.open(site)

    # all commands here return immediately
    for prog in ["xdg-open", "gnome-open"]:
        if not iscommand(prog):
            continue

        status = subprocess.check_call([prog, site])
        if status == 0:
            return True

    # sensible-browser is a debian thing
    blocking_progs = ["sensible-browser"]
    blocking_progs.extend(environ.get("BROWSER", "").split(":"))

    for prog in blocking_progs:
        if not iscommand(prog):
            continue

        # replace %s with the url
        args = prog.split()
        for i, arg in enumerate(args):
            if arg == "%s":
                args[i] = site
                break
        else:
            args.append(site)

        # calling e.g. firefox blocks, so call async and hope for the best
        try:
            spawn(args)
        except RuntimeError:
            continue
        else:
            return True

    return False
Esempio n. 10
0
def website(site):
    """Open the given URL in the user's default browser"""

    if os.name == "nt" or sys.platform == "darwin":
        return webbrowser.open(site)

    # all commands here return immediately
    for prog in ["xdg-open", "gnome-open"]:
        if not iscommand(prog):
            continue

        status = subprocess.check_call([prog, site])
        if status == 0:
            return True

    # sensible-browser is a debian thing
    blocking_progs = ["sensible-browser"]
    blocking_progs.extend(environ.get("BROWSER", "").split(":"))

    for prog in blocking_progs:
        if not iscommand(prog):
            continue

        # replace %s with the url
        args = prog.split()
        for i, arg in enumerate(args):
            if arg == "%s":
                args[i] = site
                break
        else:
            args.append(site)

        # calling e.g. firefox blocks, so call async and hope for the best
        try:
            spawn(args)
        except RuntimeError:
            continue
        else:
            return True

    return False
Esempio n. 11
0
    def test_missing(self):
        if not iscommand("intltool-update"):
            return

        old_cd = os.getcwd()
        try:
            os.chdir(PODIR)
            result = subprocess.check_output([
                "intltool-update", "--maintain", "--gettext-package",
                "quodlibet"
            ],
                                             stderr=subprocess.STDOUT)
        finally:
            os.chdir(old_cd)

        if result:
            raise Exception(result)
Esempio n. 12
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.prog_name = None

        items = self.burn_programs.items()
        progs = [(iscommand(x[1][0][0]), x) for x in items]
        progs.sort(reverse=True)

        submenu = Gtk.Menu()
        for (is_cmd, (name, (args, reverse))) in progs:
            item = Gtk.MenuItem(label=name)
            if not is_cmd:
                item.set_sensitive(False)
            else:
                connect_obj(item, 'activate', self.__set, name)
            submenu.append(item)
        self.set_submenu(submenu)
Esempio n. 13
0
    def __init__(self, *args, **kwargs):
        super(BurnCD, self).__init__(*args, **kwargs)
        self.prog_name = None

        items = self.burn_programs.items()
        progs = [(iscommand(x[1][0]), x) for x in items]
        progs.sort(reverse=True)

        submenu = Gtk.Menu()
        for (is_cmd, (name, (cmd, arg))) in progs:
            item = Gtk.MenuItem(label=name)
            if not is_cmd:
                item.set_sensitive(False)
            else:
                connect_obj(item, 'activate', self.__set, name)
            submenu.append(item)
        self.set_submenu(submenu)
Esempio n. 14
0
 def test_unix(self):
     self.failUnless(iscommand("ls"))
     self.failUnless(iscommand("/bin/ls"))
     self.failUnless(iscommand("pidof"))
Esempio n. 15
0
 def test_both(self):
     self.failIf(iscommand("zzzzzzzzz"))
     self.failIf(iscommand("/bin/zzzzzzzzz"))
     self.failIf(iscommand(""))
     self.failIf(iscommand("/bin"))
     self.failIf(iscommand("X11"))
Esempio n. 16
0
 def test_unix(self):
     self.failUnless(iscommand("ls"))
     self.failUnless(iscommand(shutil.which("ls")))
     self.failUnless(iscommand("whoami"))
Esempio n. 17
0
    @property
    def active(self):
        return self.get_active()

    # Use filter list rather than filter to avoid starting a new process
    # for each filename.
    def filter_list(self, originals, values):
        value = "\n".join(values)
        try:
            data = value.encode('shift-jis', 'replace')
        except UnicodeEncodeError:
            return values

        proc = subprocess.Popen(
            ["kakasi", "-isjis", "-osjis", "-Ha", "-Ka", "-Ja",
             "-Ea", "-ka", "-s"],
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE)
        result = proc.communicate(data)[0]

        try:
            return result.decode('shift-jis').strip().split("\n")
        except:
            return values


if not iscommand("kakasi"):
    from quodlibet import plugins
    raise plugins.PluginImportException(
        _("Couldn't find the 'Kanji Kana Simple Inverter' (kakasi)."))
Esempio n. 18
0
 def exists(self):
     return iscommand(self.command.split()[0])
Esempio n. 19
0
 def test_unix(self):
     self.failUnless(iscommand("ls"))
     self.failUnless(iscommand("/bin/ls"))
     self.failUnless(iscommand("pidof"))
Esempio n. 20
0
 def test_unix(self):
     self.failUnless(iscommand("ls"))
     self.failUnless(iscommand("/bin/ls"))
     self.failUnless(iscommand("whoami"))
Esempio n. 21
0
 def exists(self):
     res = True
     for subcommand in self.command.split("|"):
         subcommand = subcommand.lstrip().rstrip()
         res = res and iscommand(subcommand.split()[0])
     return res
Esempio n. 22
0
# Copyright 2013 Christoph Reiter
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation

import os
import glob
import subprocess
import unittest
from quodlibet.util.path import iscommand

from tests import TestCase, skipUnless


@skipUnless(iscommand("pep8"), "pep8 not found")
class TPEP8(TestCase):
    # E12x popped up in pep8 1.4 compared to 1.2..
    # drop them once 1.4 is common enough
    # E261: at least two spaces before inline comment
    IGNORE_ERROROS = ["E12", "E261"]
    PACKAGES = ("util library parse browsers devices formats "
                "plugins qltk player").split()

    def _run(self, path, ignore=None):
        if ignore is None:
            ignore = []
        ignore += self.IGNORE_ERROROS

        p = subprocess.Popen(["pep8", "--ignore=" + ",".join(ignore), path],
                             stderr=subprocess.PIPE,
Esempio n. 23
0
 def test_both(self):
     self.failIf(iscommand("zzzzzzzzz"))
     self.failIf(iscommand("/bin/zzzzzzzzz"))
     self.failIf(iscommand(""))
     self.failIf(iscommand("/bin"))
     self.failIf(iscommand("X11"))
Esempio n. 24
0
 def test_unix(self):
     self.failUnless(iscommand("ls"))
     self.failUnless(iscommand("/bin/ls"))
     self.failUnless(iscommand("whoami"))
Esempio n. 25
0
        for x in tree.iter():
            if x.tag.startswith("_"):
                x.tag = x.tag[1:]
        fd, name = mkstemp(suffix=".appdata.xml")
        os.close(fd)

        with open(name, "wb") as temp:
            header = open(self.PATH, "rb").read().splitlines()[0]
            temp.write(header + "\n")
            temp.write(ElementTree.tostring(tree.getroot(), encoding="utf-8"))

        # pass to desktop-file-validate
        try:
            subprocess.check_output(
                ["appstream-util", "validate", "--nonet", name],
                stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            raise Exception(e.output)
        finally:
            os.remove(name)


@skipUnless(iscommand("appstream-util"), "appstream-util not found")
class TQLAppDataFile(_TAppDataFile):
    PATH = os.path.join(QLDATA_DIR, "quodlibet.appdata.xml.in")


@skipUnless(iscommand("appstream-util"), "appstream-util not found")
class TEFAppDataFile(_TAppDataFile):
    PATH = os.path.join(QLDATA_DIR, "exfalso.appdata.xml.in")
Esempio n. 26
0
        for x in tree.iter():
            if x.tag.startswith("_"):
                x.tag = x.tag[1:]
        fd, name = mkstemp(suffix=".appdata.xml")
        os.close(fd)

        with open(name, "wb") as temp:
            header = open(self.PATH, "rb").read().splitlines()[0]
            temp.write(header + "\n")
            temp.write(ElementTree.tostring(tree.getroot(), encoding="utf-8"))

        # pass to desktop-file-validate
        try:
            subprocess.check_output(
                ["appstream-util", "validate", "--nonet", name],
                stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            raise Exception(e.output)
        finally:
            os.remove(name)


@skipUnless(iscommand("appstream-util"), "appstream-util not found")
class TQLAppDataFile(TestCase, _TAppDataFileMixin):
    PATH = os.path.join(QLDATA_DIR, "quodlibet.appdata.xml.in")


@skipUnless(iscommand("appstream-util"), "appstream-util not found")
class TEFAppDataFile(TestCase, _TAppDataFileMixin):
    PATH = os.path.join(QLDATA_DIR, "exfalso.appdata.xml.in")
Esempio n. 27
0
 def exists(self):
     res = True
     for subcommand in self.command.split("|"):
         subcommand = subcommand.lstrip().rstrip()
         res = res and iscommand(subcommand.split()[0])
     return res
Esempio n. 28
0
# Copyright 2013 Christoph Reiter
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation

import os
import glob
import subprocess

from quodlibet.util.path import iscommand

from tests import TestCase, skipUnless


@skipUnless(iscommand("pep8"), "pep8 not found")
class TPEP8(TestCase):
    # E12x popped up in pep8 1.4 compared to 1.2..
    # drop them once 1.4 is common enough
    # E261: at least two spaces before inline comment
    IGNORE_ERROROS = ["E12", "E261", "E265", "E713", "W602", "E402", "E731", "W503"]

    def _run(self, path, ignore=None):
        if ignore is None:
            ignore = []
        ignore += self.IGNORE_ERROROS

        p = subprocess.Popen(
            ["pep8", "--ignore=" + ",".join(ignore), path], stderr=subprocess.PIPE, stdout=subprocess.PIPE
        )