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 50 58 60 66 67 69 70 71 72 73 74 75 76 77 78 79 81 83 84 85 96 97 99 100 103 104 107 108 113 114 119 120 122 123 124 125 128 129 131 132 133 134 136 137 139 140 141 142 143 144 145 148 149 150 152 153 157 158 161 162 163 168 171 172 174 175 176 177 179 180 182 183 184 185 186 187 188 191 192 193 197 198 202 203 206 207 208 214 215 216 217 219 220 221 223 225 226 228 229 231 232 234 235 237 238 240 241 243 244 246 247 249 250 252 253 254 255 256 257 259 260 262 263 264 266 268 269 271 272 274 275 277 278 279 284 285 287 292 295 298 299 300 301 302 303 305 307 308 310 312 313 316 318 319 322 324 325 328 332 334 336 338 340 343 344 347 349 353 355 357 361 362 364 367 369 370 371 372 373 375 376 378 379 381 382 384 385 387 388 390 391 393 394 396 398 402 404 405 408 411 413 414 416 420 425 427 428 429 430 437 444 445 448 449 451 454 455 457 460 464 466 473 474 476 479 480 482 483 485 487 488 489 491 492 494 496 497 498 499 500 501 502 503 504 505 506 507 509 510 513 515 517 518 519 520 521 522 523 524 525 526 527 528 529 530 532 533 534 535 538 540 542 543 544 545 546 547 548 549 550 551 552 553 554 555 557 558 560 562 563 564 566 567 568 570 571 573 575 578 579 581 585 586 590 591 593 602 603 605 607 608 609 610 611 612 613 614 615 616 617 618 620 621 623 624 626 627 628 630 631 632 634 635 637 639 640 641 643 644 645 646 647 648 649 650 651 652 654 655 658 661 663 664 666 667 668 669 670 671 672 673 675 676 677 679 680 681 683 684 686 687 688 689 690 691 692 693 694 695 697 699 700 702 703 704 705 706 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 744 745 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 783 |
# -*- test-case-name: bloggerfs.test_bloggerfs -*-
# bloggerfs.py - blogger file system in userspace using FUSE # Copyright (C) 2010 Marco Giusti # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This library 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 # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this library; if not, write to the Free # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, # MA 02111-1307, USA
# rfc3339.py -- Implementation of the majority of RFC 3339 for python. # Copyright (c) 2008, 2009, 2010 LShift Ltd. <query@lshift.net>
# gdata - Python client library for Google data APIs # Copyright (C) 2009 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.
'CommentNode', 'DirEntry', 'DirNode', 'ElementNode', 'EntryNode', 'FeedEntryNode', 'FileNode', 'DictNode', 'publishedFactory', 'updatedFactory', 'registerAdapter2', 'registerAdapter', 'IDirNode', 'IFileNode', 'INode', 'IPublished', 'IUpdated', 'ListNode', 'Node', 'PostNode', 'TextNode', 'TimeOutMixin', 'AddCommentNode', 'AddLabelNode', '__author__', '__copyright__', '__email__', '__license__', '__version__', 'client', 'getType', 'main']
pass
"""Return all members of an object as (name, value) pairs sorted by name. Optionally, only return members that satisfy a given predicate.""" else: mro = (obj,) # First try to get the value via __dict__. Some descriptors don't # like calling their __get__ (see bug #1785). else: value = getattr(obj, key)
# Taken from Twisted
""" Return the adapter factory for the given parameters in the given registry, or None if there is not one. """
"""Register an adapter class.
An adapter class is expected to implement the given interface, by adapting instances implementing 'origInterface'. An adapter class's __init__ method should accept one parameter, an instance implementing 'origInterface'. """ global ALLOW_DUPLICATES
# deal with class->interface adapters: origInterface = declarations.implementedBy(origInterface)
raise ValueError("an adapter (%s) was already registered." % (factory, ))
# add global adapter lookup hook for our newly created registry else:
""" Return the adapter factory for the given parameters in the given registry, or None if there is not one. """
"""Register an adapter class.
An adapter class is expected to implement the given interfaces, by adapting instances implementing ('iface1', 'iface2'). An adapter class's __init__ method should accept two parameters, the instances implementing 'iface1' and 'iface2'. """ global ALLOW_DUPLICATES
# deal with class->interface adapters: iface2 = declarations.implementedBy(iface2)
raise ValueError("an adapter (%s) was already registered." % (factory, ))
# add global adapter lookup hook for our newly created registry
# End taken
""""""
"""File open operation"""
""""""
""""""
""""""
""""""
""""""
""""""
""""""
""""""
"""Get file attributes.
Similar to stat(). The 'st_dev' and 'st_blksize' fields are ignored. The 'st_ino' field is ignored except if the 'use_ino' mount option is given."""
""""""
""""""
""""""
""""""
""""""
""""""
self.type != other.type or self.ino != other.ino:
def __repr__(self): type = self.type == stat.S_IFREG and 'file' or 'dir' return '<bloggerfs.DirEntry name="%s", type="%s">' % (self.name, type)
def mtime(self):
def ctime(self):
def text(self):
st_uid=os.getuid(), st_gid=os.getgid(), st_size=size, st_ctime=self.ctime, st_mtime=self.mtime)
# parent = IFileNode(self.parent, None) # if parent: # return parent.write(buf, offset, fh=None) raise IOError(errno.EACCES, 'Permission denied')
return 0
return 0
return 0
return 0
return 0
return 0
def text(self):
return {}
def children(self):
if k not in self.children: raise IOError(errno.ENOENT, 'No such file or directory') del self.children[k]
# yield IEntry((name, node))
st_uid=os.geteuid(), st_gid=os.getegid(), st_size=4096, st_ctime=self.ctime, st_mtime=self.mtime)
def children(self):
for i, el in enumerate(self.original))
return dict((str(k), INode((v, self))) for k, v in self.original.iteritems())
children = {} for name, member_type in self.original._members: if isinstance(member_type, tuple): continue
element = getattr(self.original, name) if element is not None: children[name] = INode((element, self)) if self.original.text: children['text'] = INode((self.original.text, self)) return children
def updated(self): if self._updated is None: if self.original.updated: try: updated = self.original.updated.text updated = rfc3339.parse_datetime(updated) self._updated = int(time.mktime(updated.timetuple())) except: _exception('') self._updated = int(time.time()) else: self._updated = int(time.time()) return self._updated
def blogId(self): return self.original.get_blog_id()
def published(self): if self._published is None: if self.original.published: try: published = self.original.published.text published = rfc3339.parse_datetime(published) self._published = int(time.mktime(published.timetuple())) except: _exception('') self._published = self.mtime else: self._published = self.mtime return self._published
def id(self): return self.original.get_comment_id()
client.delete(self.original) self.parent.deleteChild(self.id)
self.parent.get_post_id(), buf, body_type='text')
children = EntryNode.getChildren(self) try: feed = client.get_post_comments(self.blogId, self.id) except gdata.client.RequestError: _exception('') else: comments = dict((e.get_comment_id(), e) for e in feed.entry) children['comments'] = INode((comments, self)) children['add_comment'] = AddCommentNode('', self) children['add_label'] = AddLabelNode('', self) return children
return self.original.get_post_id()
return self.original.get_blog_id()
def id(self): return self.get_post_id()
client.delete(self.original) self.parent.deleteChild(self.id)
def id(self): return self.original.get_blog_id()
children = FeedEntryNode.getChildren(self) try: feed = client.get_posts(self.blogId) except gdata.client.RequestError: _exception('') else: posts = dict((e.get_post_id(), e) for e in feed.entry) children['posts'] = INode((posts, self)) return children
pass
def original(self): if self._original is None: try: self._original = client.get_blogs() except gdata.client.RequestError, e: raise IOError(errno.EIO, e.reason) return self._original
def parent(self): return self
return dict((e.get_blog_id(), INode((e, self))) for e in self.original.entry)
@functools.wraps def wrapper(*args, **kwds): try: return f(*args, **kwds) except: _exception('Error in fuse api') raise return wrapper
'release', 'truncate', 'fsync', 'utime', 'rename'])
fuse.Fuse.__init__(self, *args, **kwds) global client client = gdata.blogger.client.BloggerClient() self._account = AccountNode(None, None)
if self.parser.fuse_args.mount_expected(): options = self.cmdline[0] if options.debug: _logger.setLevel(logging.DEBUG) if options.syslog: from logging import handlers handler = handlers.SysLogHandler() elif options.logfile: from logging import handlers handler = handlers.FileHandler(options.logfile) elif options.debug: handler = logging.StreamHandler() else: handler = NullHandler() formatter = logging.Formatter('[%(asctime)s] [%(levelname)s] ' '[%(funcName)s] %(message)s') handler.setFormatter(formatter) _logger.addHandler(handler)
if not options.email: from gdata.sample_util import authorize_client authorize_client(client, service='blogger', source='bloggerfs', scopes=['http://www.blogger.com/feeds/']) else: email = options.email if not options.password: import getpass password = getpass.getpass() else: password = options.password client.client_login(email, password, source='bloggerfs', service='blogger') fuse.Fuse.main(self)
return (path.split('/')[1:], [])[path == '/']
if name in self._fuse_api: def _(path, *args, **kwds): try: parts = self._splitpath(path) node = self._account.locate(parts) func = getattr(node, name, None) if func is None: raise IOError(errno.ENOSYS, 'Function %s not ' 'implemented' % name) return func(*args, **kwds) except: _exception('Error in %s' % name) raise return _ raise AttributeError(name)
if argv is None: import sys argv = sys.argv[1:]
server = BloggerFS() server.parser.add_option('-e', '--email', help='Google account email') server.parser.add_option('-p', '--password', help='Google account password') server.parser.add_option('-b', '--debug', help='Show debugging info', action='store_true') server.parser.add_option('--syslog', action='store_true', help='Log messages to syslog') server.parser.add_option('-l', '--logfile', help='Log messages to file') server.parse(args=argv, errex=1) server.main()
main() |