File: rpy_io.py

package info (click to toggle)
rpy 0.4.1-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,988 kB
  • ctags: 14,206
  • sloc: ansic: 15,392; python: 977; makefile: 406; sh: 28
file content (52 lines) | stat: -rw-r--r-- 1,530 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
#  Basic io.
#
#  $Id: rpy_io.py,v 1.5 2004/02/27 17:05:40 warnes Exp $
#
#

import sys
import os

# Input and output to sys.std{in,out}
def rpy_output(s):
    sys.stdout.write(s)

def rpy_input(prompt, n):
    rpy_output(prompt)
    return sys.stdin.readline()[:n-1]


# Show the files in a terminal with a standard pager
def showfiles_tty(files, headers, title, delete):
    PAGER = 'less'
    for file, header in zip(files, headers):
        os.system('%(PAGER)s %(file)s' %locals())


# Show the files via R_stdout (useful for using with idle)
def showfiles_common(files, headers, title, delete):
    rpy_output(title)
    for file, header in zip(files, headers):
        rpy_output(header)
        for line in open(file).readlines():
            rpy_output(line)


# Default
rpy_showfiles = showfiles_common