diff options
| author | eroen | 2013-07-24 01:11:57 +0200 |
|---|---|---|
| committer | eroen | 2013-07-24 01:11:57 +0200 |
| commit | 55c218020baebaa4230bfdad9a488bfe496361d7 (patch) | |
| tree | d4adc2af87b6c60a1f9f9f4a96985489e1f52ace | |
| download | echoboom-fuse-master.tar.gz echoboom-fuse-master.tar.bz2 echoboom-fuse-master.tar.xz | |
| -rwxr-xr-x | echoboom-fuse.py | 99 | ||||
| -rwxr-xr-x | ircbot.py | 34 |
2 files changed, 133 insertions, 0 deletions
diff --git a/echoboom-fuse.py b/echoboom-fuse.py new file mode 100755 index 0000000..41564bc --- /dev/null +++ b/echoboom-fuse.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python2.7 + +# Copyright (C) 2006 Andrew Straw <strawman@astraw.com> +# +# This program can be distributed under the terms of the GNU LGPL. +# See the file COPYING. +# + +import os +import stat +import errno +# pull in some spaghetti to make this stuff work without fuse-py being +# installed +try: + import _find_fuse_parts +except ImportError: + pass +import fuse +from fuse import Fuse + + +if not hasattr(fuse, '__version__'): + raise RuntimeError, \ + "your fuse-py doesn't know of fuse.__version__, probably it's too old." + +fuse.fuse_python_api = (0, 2) + +hello_path = '/hello' +hello_str = 'Hello World!\n' + + +class MyStat(fuse.Stat): + + def __init__(self): + self.st_mode = 0 + self.st_ino = 0 + self.st_dev = 0 + self.st_nlink = 0 + self.st_uid = 0 + self.st_gid = 0 + self.st_size = 0 + self.st_atime = 0 + self.st_mtime = 0 + self.st_ctime = 0 + + +class HelloFS(Fuse): + + def getattr(self, path): + st = MyStat() + if path == '/': + st.st_mode = stat.S_IFDIR | 0755 + st.st_nlink = 2 + elif path == hello_path: + st.st_mode = stat.S_IFREG | 0444 + st.st_nlink = 1 + st.st_size = len(hello_str) + else: + return -errno.ENOENT + return st + + def readdir(self, path, offset): + for r in '.', '..', hello_path[1:]: + yield fuse.Direntry(r) + + def open(self, path, flags): + if path != hello_path: + return -errno.ENOENT + accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR + if (flags & accmode) != os.O_RDONLY: + return -errno.EACCES + + def read(self, path, size, offset): + if path != hello_path: + return -errno.ENOENT + slen = len(hello_str) + if offset < slen: + if offset + size > slen: + size = slen - offset + buf = hello_str[offset:offset + size] + else: + buf = '' + return buf + + +def main(): + usage = """ +Userspace hello example + +""" + Fuse.fusage + server = HelloFS(version="%prog " + fuse.__version__, + usage=usage, + dash_s_do='setsingle') + + server.parse(errex=1) + server.main() + +if __name__ == '__main__': + main() diff --git a/ircbot.py b/ircbot.py new file mode 100755 index 0000000..701efec --- /dev/null +++ b/ircbot.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python2.7 +import socket + +def main(): + network = 'chat.freenode.org' + port = 6667 + irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + irc.connect((network, port)) + print irc.recv(4096) + mychan = '#echoboom' + irc.send('NICK echoboom-fuse-bot1\r\n') + irc.send('USER botty botty botty :Python IRC\r\n') + irc.send('JOIN ' + mychan + '\r\n') + irc.send('PRIVMSG #Paul :Hello World.\r\n') + while True: + data = irc.recv(4096) + if data.find('PING') != -1: + irc.send('PONG ' + data.split()[1] + '\r\n') + if data.find('!botty quit') != -1: + irc.send('PRIVMSG ' + mychan + ' :Fine, if you don''t want me\r\n') + irc.send('QUIT\r\n') + if data.find('hi botty') != -1: + irc.send('PRIVMSG ' + mychan + ' :I already said hi...\r\n') + if data.find('hello botty') != -1: + irc.send('PRIVMSG ' + mychan + ' :I already said hi...\r\n') + if data.find('KICK') != -1: + irc.send('JOIN ' + mychan + '\r\n') + if data.find('cheese') != -1: + irc.send('PRIVMSG ' + mychan + ' :WHERE!!!!!!\r\n') + if data.find('slaps botty') != -1: + irc.send('PRIVMSG ' + mychan + ' :This is the Trout Protection Agency. Please put the Trout Down and walk away with your hands in the air.\r\n') + print data + +main() |
