| Server IP : 182.53.201.61 / Your IP : 216.73.217.175 Web Server : Apache/2.2.15 (Fedora) System : Linux km10.dyndns.org 2.6.31.5-127.fc12.i686.PAE #1 SMP Sat Nov 7 21:25:57 EST 2009 i686 User : apache ( 48) PHP Version : 5.3.3 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /proc/3628/root/usr/share/doc/gnome-python2-gnomevfs-2.28.0/ |
Upload File : |
#!/usr/bin/env python
import os
_boldcode = os.popen('tput bold', 'r').read()
_normal = os.popen('tput rmso', 'r').read()
import pygtk; pygtk.require("2.0")
import gnomevfs
class Shell:
def __init__(self, cwd=None):
if cwd:
self.cwd = gnomevfs.URI(cwd)
else:
self.cwd = gnomevfs.URI(os.getcwd())
if str(self.cwd)[-1] != '/':
self.cwd = self.cwd.append_string('/')
def run(self):
while 1:
try:
line = raw_input('%s%s$%s ' % (_boldcode, self.cwd, _normal))
words = line.split()
command = getattr(self, words[0])
args = words[1:]
command(*args)
except KeyboardInterrupt:
break
except EOFError:
break
except Exception, e:
print "Error: %s:%s" % (e.__class__.__name__, str(e))
def cd(self, dir):
new_cwd = self.cwd.resolve_relative(dir)
if str(new_cwd)[-1] != '/':
new_cwd = new_cwd.append_string('/')
if gnomevfs.get_file_info(new_cwd).type != \
gnomevfs.FILE_TYPE_DIRECTORY:
raise gnomevfs.error('%s is not a directory' % dir)
self.cwd = new_cwd
def pwd(self):
print str(self.cwd)
def ls(self, dir=''):
dir = self.cwd.resolve_relative(dir)
dhandle = gnomevfs.open_directory(dir)
for file_info in dhandle:
print file_info.name
def less(self, file):
file = self.cwd.resolve_relative(file)
file_info = gnomevfs.get_file_info(file)
fp = gnomevfs.open(file, gnomevfs.OPEN_READ)
less = os.popen('less -m -F -', 'w')
buffer = fp.read(file_info.size)
less.write(buffer)
less.close()
more = less
cat = less
def stat(self, file):
file = self.cwd.resolve_relative(file)
file_info = gnomevfs.get_file_info(file, gnomevfs.FILE_INFO_GET_MIME_TYPE)
print 'Name: ', file_info.name
file_type = '(none)'
try: file_type = ('unknown', 'regular', 'directory',
'fifo', 'socket', 'chardev', 'blockdev',
'symlink')[file_info.type]
except: pass
print 'Type: ', file_type
file_size = '(unknown)'
try: file_size = file_info.size
except: pass
print 'Size: ', file_size
mime_type = '(none)'
try: mime_type = file_info.mime_type
except: pass
print 'Mime type: ', mime_type
if __name__ == '__main__':
shell = Shell()
shell.run()
print