コード例 #1
0
def test_simple_webkit():
    cmd = "python {webkit} '{url}'".format(webkit=cfg.SIMPLE_WEBKIT, url=URL)
    
    text = process.get_simple_cmd_output(cmd)
    assert '<h1 id="message">Hi Crowbar!</h1>' in text
    # call it again:
    text = process.get_simple_cmd_output(cmd)
    assert '<h1 id="message">Hi Crowbar!</h1>' in text
コード例 #2
0
def get_wmctrl_output():
    """
    Parses the output of wmctrl and returns a list of ordered dicts.
    """
    assert fs.which("wmctrl"), "the program wmctrl was not found."
    #
    cmd = "wmctrl -lGpx"
    lines = [
        line for line in process.get_simple_cmd_output(cmd).split("\n") if line
    ]

    res = []
    for line in lines:
        # 0x05e000c7  0 4402   2562 298  638  540  truecrypt.Truecrypt   jabba-uplink TrueCrypt
        pieces = line.split()
        d = OrderedDict()
        #d['wid'] = int(pieces[0], 16)  # converted to decimal
        d['wid'] = pieces[0]
        d['desktop'] = int(pieces[1])
        d['pid'] = int(pieces[2])
        d['geometry'] = [int(x) for x in pieces[3:7]]
        d['window_class'] = pieces[7]
        d['client_machine_name'] = pieces[8]
        d['window_title'] = ' '.join(pieces[9:])
        res.append(d)
    #
    return res
コード例 #3
0
ファイル: platform.py プロジェクト: ayoub-benali/jabbapylib
def get_screen_resolution():
    """
    Screen resolution (as a tuple).
    """
    result = [x for x in process.get_simple_cmd_output(cfg.XRANDR).split('\n') if '*' in x][0]
    result = tuple([int(x) for x in result.split()[0].split('x')])
    return result
コード例 #4
0
ファイル: window.py プロジェクト: jeffreywinn/jabbapylib
def get_wmctrl_output():
    """
    Parses the output of wmctrl and returns a list of ordered dicts.
    """
    assert fs.which("wmctrl"), "the program wmctrl was not found."
    #
    cmd = "wmctrl -lGpx"
    lines = [line for line in process.get_simple_cmd_output(cmd).split("\n") if line]

    res = []
    for line in lines:
# 0x05e000c7  0 4402   2562 298  638  540  truecrypt.Truecrypt   jabba-uplink TrueCrypt
        pieces = line.split()
        d = OrderedDict()
        #d['wid'] = int(pieces[0], 16)  # converted to decimal
        d['wid'] = pieces[0]
        d['desktop'] = int(pieces[1])
        d['pid'] = int(pieces[2])
        d['geometry'] = [int(x) for x in pieces[3:7]]
        d['window_class'] = pieces[7]
        d['client_machine_name'] = pieces[8]
        d['window_title'] = ' '.join(pieces[9:])
        res.append(d)
    #
    return res
コード例 #5
0
def get_video_summary(video_file):
    """Get a one-line summary of the video file.

    Example: 'VIDEO:  [WMV3]  320x240  24bpp  1000.000 fps  386.0 kbps (47.1 kbyte/s)'
    """
    cmd = video_info.format(video_file)
    output = process.get_simple_cmd_output(cmd)
    return re.findall("VIDEO\:.*", output)[0]
コード例 #6
0
ファイル: ping.py プロジェクト: jeffreywinn/jabbapylib
def ping(host, cnt=1):
    """Ping a URL and return the average ping time."""
    cmd = 'ping -c {cnt} {url}'.format(url=host, cnt=cnt)
    output = [x for x in process.get_simple_cmd_output(cmd).split('\n') if x]
    result = re.search('min/avg/max/mdev = (.*)/(.*)/(.*)/(.*) ms', output[-1])
    if result:
        return float('{0:.2f}'.format(float(result.group(1))))
    else:
        return None
コード例 #7
0
ファイル: ping.py プロジェクト: the7day/jabbapylib
def ping(host, cnt=1):
    """Ping a URL and return the average ping time."""
    cmd = 'ping -c {cnt} {url}'.format(url=host, cnt=cnt)
    output = [x for x in process.get_simple_cmd_output(cmd).split('\n') if x]
    result = re.search('min/avg/max/mdev = (.*)/(.*)/(.*)/(.*) ms', output[-1])
    if result:
        return float('{0:.2f}'.format(float(result.group(1))))
    else:
        return None
コード例 #8
0
def get_video_info(video_file):
    """Get info about a video.

    The info is returned by mplayer. The result is a
    dictionary whose keys start with 'ID_'.
    """
    cmd = video_info.format(video_file)
    output = process.get_simple_cmd_output(cmd)
    return dict(re.findall('(ID_.*)=(.*)', output))
コード例 #9
0
ファイル: podium.py プロジェクト: the7day/jabbapylib
def get_screen_resolution():
    """
    Screen resolution (as a tuple).
    """
    result = [
        x for x in process.get_simple_cmd_output(cfg.XRANDR).split('\n')
        if '*' in x
    ][0]
    result = tuple([int(x) for x in result.split()[0].split('x')])
    return result
コード例 #10
0
def get_window_title_by_id(wid):
    assert fs.which("xwininfo"), "the program xwininfo was not found."
    #
    result = get_simple_cmd_output('xwininfo -id {id}'.format(id=wid))
    for line in StringIO(result):
        line = line.rstrip("\n")
        match = re.search(r'^xwininfo: Window id:.*"(.*)"$', line)
        if match:
            return match.group(1)
    #
    return None
コード例 #11
0
ファイル: window.py プロジェクト: demonmerlin/jabbapylib
def get_window_title_by_id(wid):
    assert fs.which("xwininfo"), "the program xwininfo was not found."
    #
    result = get_simple_cmd_output('xwininfo -id {id}'.format(id=wid))
    for line in StringIO(result):
        line = line.rstrip("\n")
        match = re.search(r'^xwininfo: Window id:.*"(.*)"$', line)
        if match:
            return match.group(1)
    #
    return None
コード例 #12
0
ファイル: web.py プロジェクト: ayoub-benali/jabbapylib
def get_page_with_cookies_using_wget(url):
    """Get the content of a cookies-protected page.
    
    The page is downloaded with wget. Cookies are passed to wget."""
    cookies = get_cookies_in_text(get_host(url))
    fs.store_content_in_file(cookies, cfg.COOKIES_TXT, overwrite=True)
    OPTIONS = "--cookies=on --load-cookies={0} --keep-session-cookies".format(cfg.COOKIES_TXT)
    cmd = "{wget} {options} '{url}' -qO-".format(wget=cfg.WGET, options=OPTIONS, url=url)
    page = process.get_simple_cmd_output(cmd)
    os.unlink(cfg.COOKIES_TXT)
    
    return page
コード例 #13
0
ファイル: ping.py プロジェクト: jeffreywinn/jabbapylib
def fping(host, cnt=1):
    """
    Get the avg ping time of a host (in msec).

    Instead of ping we use the command fping.
    """
    host = host.split(':')[0]
    cmd = "fping {host} -C {cnt} -q".format(host=host, cnt=cnt)
    res = [float(x) for x in process.get_simple_cmd_output(cmd).strip().split(':')[-1].split() if x != '-']
    if len(res) > 0:
        return sum(res) / len(res)
    else:
        return None
コード例 #14
0
ファイル: window.py プロジェクト: demonmerlin/jabbapylib
def get_active_window_id(hexa=False):
    """
    Window ID of the active window.

    The return value is a string. By default, the ID is in decimal
    format. If hexa is True, the return value is hexadecimal.
    In both cases, the return value is a string.
    """
    assert fs.which("xdotool"), "the program xdotool was not found."
    #
    wid = get_simple_cmd_output('xdotool getactivewindow').strip()
    if not hexa:
        return wid
    else:
        return hex(int(wid))
コード例 #15
0
def get_active_window_id(hexa=False):
    """
    Window ID of the active window.

    The return value is a string. By default, the ID is in decimal
    format. If hexa is True, the return value is hexadecimal.
    In both cases, the return value is a string.
    """
    assert fs.which("xdotool"), "the program xdotool was not found."
    #
    wid = get_simple_cmd_output('xdotool getactivewindow').strip()
    if not hexa:
        return wid
    else:
        return hex(int(wid))
コード例 #16
0
def get_page_with_cookies_using_wget(url):
    """Get the content of a cookies-protected page.

    The page is downloaded with wget. Cookies are passed to wget."""
    cookies = get_cookies_in_text(get_host(url))
    fs.store_content_in_file(cookies, cfg.COOKIES_TXT, overwrite=True)
    OPTIONS = "--cookies=on --load-cookies={0} --keep-session-cookies".format(
        cfg.COOKIES_TXT)
    cmd = "{wget} {options} '{url}' -qO-".format(wget=cfg.WGET,
                                                 options=OPTIONS,
                                                 url=url)
    page = process.get_simple_cmd_output(cmd)
    os.unlink(cfg.COOKIES_TXT)

    return page
コード例 #17
0
ファイル: ping.py プロジェクト: the7day/jabbapylib
def fping(host, cnt=1):
    """
    Get the avg ping time of a host (in msec).

    Instead of ping we use the command fping.
    """
    host = host.split(':')[0]
    cmd = "fping {host} -C {cnt} -q".format(host=host, cnt=cnt)
    res = [
        float(x) for x in process.get_simple_cmd_output(cmd).strip().split(':')
        [-1].split() if x != '-'
    ]
    if len(res) > 0:
        return sum(res) / len(res)
    else:
        return None
コード例 #18
0
ファイル: web.py プロジェクト: ayoub-benali/jabbapylib
def html_to_text(html, method=cfg.LYNX):
    """Convert an HTML source to text format. Two methods are available:
    (1) with lynx, (2) with html2text.py.
    
    The return value is a string.""" 
    temp = tempfile.NamedTemporaryFile(prefix='tmp', suffix='.html', dir='/tmp', delete=False)
    fs.store_content_in_file(html, temp.name, overwrite=True)
    if method == cfg.LYNX:
        cmd = "{lynx} {html} -dump".format(lynx=cfg.LYNX, html=temp.name)
    elif method == cfg.HTML2TEXT:
        cmd = "python {html2text} {html}".format(html2text=cfg.HTML2TEXT, html=temp.name)
    else:
        print >>sys.stderr, "Warning! Unknown method is used in web.html_to_text."
        os.unlink(temp.name)
        return None
    
    text = process.get_simple_cmd_output(cmd)
    os.unlink(temp.name)
    return text
コード例 #19
0
def html_to_text(html, method=cfg.LYNX):
    """Convert an HTML source to text format. Two methods are available:
    (1) with lynx, (2) with html2text.py.

    The return value is a string."""
    temp = tempfile.NamedTemporaryFile(prefix='tmp',
                                       suffix='.html',
                                       dir='/tmp',
                                       delete=False)
    fs.store_content_in_file(html, temp.name, overwrite=True)
    if method == cfg.LYNX:
        cmd = "{lynx} {html} -dump".format(lynx=cfg.LYNX, html=temp.name)
    elif method == cfg.HTML2TEXT:
        cmd = "python {html2text} {html}".format(html2text=cfg.HTML2TEXT,
                                                 html=temp.name)
    else:
        print >> sys.stderr, "Warning! Unknown method is used in web.html_to_text."
        os.unlink(temp.name)
        return None

    text = process.get_simple_cmd_output(cmd)
    os.unlink(temp.name)
    return text
コード例 #20
0
ファイル: gnome3.py プロジェクト: jeffreywinn/jabbapylib
def get_wallpaper():
    """Get the path of the file that is set as wallpaper."""

    cmd = 'gsettings get org.gnome.desktop.background picture-uri'
    uri = process.get_simple_cmd_output(cmd)
    return uri.replace("'", "")
コード例 #21
0
ファイル: clipboard.py プロジェクト: ayoub-benali/jabbapylib
def read_clipboard():
    """Read content of 'clipboard'."""
    cmd = 'xsel -bo'
    return process.get_simple_cmd_output(cmd)
コード例 #22
0
ファイル: clipboard.py プロジェクト: the7day/jabbapylib
def read_primary():
    """Read content of 'primary'."""
    cmd = 'xsel -po'
    return process.get_simple_cmd_output(cmd)
コード例 #23
0
ファイル: clipboard.py プロジェクト: the7day/jabbapylib
def read_clipboard():
    """Read content of 'clipboard'."""
    cmd = 'xsel -bo'
    return process.get_simple_cmd_output(cmd)
コード例 #24
0
ファイル: gnome.py プロジェクト: ayoub-benali/jabbapylib
def get_gnome_session_version():
    version = process.get_simple_cmd_output('gnome-session --version')
    return int(version.split()[1][0])    # main version number
コード例 #25
0
ファイル: web.py プロジェクト: ayoub-benali/jabbapylib
def get_js_page(url):
    """Get a page with Webkit, i.e. evaluate embedded Javascripts."""
    cmd = "python {webkit} '{url}'".format(webkit=cfg.SIMPLE_WEBKIT, url=url)
    text = process.get_simple_cmd_output(cmd)
    return text
コード例 #26
0
 def test_get_unix_date(self):
     # Unix command 'date'
     date = process.get_simple_cmd_output('date').replace('\n', '')
     # pure Python 'date'
     python = dat.get_unix_date()
     assert date == python
コード例 #27
0
ファイル: test_process.py プロジェクト: the7day/jabbapylib
def test_get_simple_cmd_output():
    res = process.get_simple_cmd_output("echo -n Ubuntu")
    assert res == 'Ubuntu'
コード例 #28
0
ファイル: clipboard.py プロジェクト: ayoub-benali/jabbapylib
def read_primary():
    """Read content of 'primary'."""
    cmd = 'xsel -po'
    return process.get_simple_cmd_output(cmd)
コード例 #29
0
ファイル: gnome2.py プロジェクト: ayoub-benali/jabbapylib
def get_wallpaper():
    """Get the path of the file that is set as wallpaper."""

    cmd = "gconftool-2 --get /desktop/gnome/background/picture_filename"
    return process.get_simple_cmd_output(cmd)
コード例 #30
0
 def test_get_unix_date(self):
     # Unix command 'date'
     date = process.get_simple_cmd_output('date').replace('\n', '')
     # pure Python 'date'
     python = dat.get_unix_date()
     assert date == python
コード例 #31
0
ファイル: gnome2.py プロジェクト: the7day/jabbapylib
def get_wallpaper():
    """Get the path of the file that is set as wallpaper."""

    cmd = "gconftool-2 --get /desktop/gnome/background/picture_filename"
    return process.get_simple_cmd_output(cmd)
コード例 #32
0
ファイル: gnome.py プロジェクト: the7day/jabbapylib
def get_gnome_session_version():
    version = process.get_simple_cmd_output('gnome-session --version')
    return int(version.split()[1][0])  # main version number
コード例 #33
0
def test_get_simple_cmd_output():
    res = process.get_simple_cmd_output("echo -n Ubuntu")
    assert res == 'Ubuntu'