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 52 60 62 68 69 71 74 75 86 87 89 90 93 94 97 98 103 104 109 110 112 113 114 115 118 119 121 122 123 124 126 127 129 130 131 132 133 134 135 138 139 140 143 147 148 151 152 153 158 161 162 163 164 166 167 168 170 172 173 175 176 178 179 181 182 184 185 187 188 190 191 193 194 196 197 199 200 201 202 203 204 206 207 209 210 211 213 215 216 218 219 221 222 224 225 226 228 230 231 233 235 236 241 242 245 246 248 253 256 259 260 261 262 263 264 267 269 270 273 275 276 279 283 285 287 289 291 294 295 296 299 301 305 307 309 313 314 316 319 321 322 324 325 327 328 330 331 333 334 336 337 339 340 342 343 345 347 351 353 354 357 360 362 363 365 369 374 376 377 378 379 385 392 399 400 403 404 406 409 410 412 415 419 421 428 429 431 434 435 437 438 440 442 443 444 446 447 449 451 452 453 454 455 456 457 458 459 460 461 462 464 465 466 467 468 469 470 471 472 473 474 475 478 480 482 483 484 485 486 487 488 489 490 491 492 493 494 495 497 498 499 500 503 505 507 508 509 510 511 512 513 514 515 516 517 518 519 520 522 523 525 527 528 529 531 532 533 535 536 538 540 543 552 557 558 560 562 565 566 567 568 570 572 573 575 580 581 583 584 586 587 588 589 590 591 592 593 594 595 596 597 599 600 602 603 605 606 607 608 609 610 611 612 613 615 616 617 619 620 622 626 627 628 629 633 634 635 638 642 643 644 645 646 647 648 649 650 651 653 655 656 657 659 660 661 662 663 664 665 666 667 668 669 671 672 675 678 680 681 683 684 685 686 687 688 689 690 692 693 694 696 697 698 699 700 701 702 703 705 706 708 709 710 711 712 713 714 715 716 717 719 721 722 724 725 726 727 728 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 766 767 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 805 |
# -*- 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.
"""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:
raise ValueError("an adapter (%s) was already registered." % (factory, ))
# add global adapter lookup hook for our newly created registry else:
# 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)
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), self.buildChildNode(v)) 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] = self.buildChildNode(element) if self.original.text: children['text'] = self.buildChildNode(self.original.text) return children
# class LabelNode(ElementNode):
# def rmdir(self): # post = self.getParent(IPost, self.parent) # if post is not None: # post.deleteLabel(self) # return 0 # raise IOError(errno.EACCES, 'Permission denied')
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)
raise
self.parent.get_post_id(), buf, body_type=self.type)
# implements(IPost)
children = EntryNode.getChildren(self) try: feed = client.get_post_comments(self.blogId, self.id) comments = dict((e.get_comment_id(), e) for e in feed.entry) children['comments'] = self.buildChildNode(comments) children['add_comment'] = AddCommentNode('', self) children['add_html_comment'] = AddHtmlCommentNode('', self) children['add_label'] = AddLabelNode('', self) except gdata.client.RequestError: _exception('') return children
return self.original.get_post_id()
return self.original.get_blog_id()
def id(self): return self.get_post_id()
# def deleteLabel(self, labelNode): # if 'category' in self.children: # cat = self.getChild('category') # if not self.dirty: # self.dirty = True
client.delete(self.original) self.parent.deleteChild(self.id)
def getEntry(feed): if len(feed.entry) > 0: return feed.entry[0]
def getEntry(entry): return entry
if element is None: continue entry = target.getEntry(element) if entry is not None: client.post(entry, gdata.blogger.client.BLOG_POST_URL % self.parent.blogId) return raise IOError(errno.EINVAL, 'Cannot parse xml to a valid class')
def id(self): return self.original.get_blog_id()
children = FeedEntryNode.getChildren(self) children['add_post'] = AddPostNode('', 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'] = self.buildChildNode(posts) 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(), self.buildChildNode(e)) for e in self.original.entry)
# def getParent(self, iface): # if iface.providedBy(self): # return self # return None
@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() |