Revision 29148653 snf-pithos-backend/pithos/backends/lib/sqlite/node.py

b/snf-pithos-backend/pithos/backends/lib/sqlite/node.py
246 246
    def node_get_versions(self, node, keys=(), propnames=_propnames):
247 247
        """Return the properties of all versions at node.
248 248
           If keys is empty, return all properties in the order
249
           (serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster).
249
           (serial, node, hash, size, type, source, mtime, muser, uuid,
250
            checksum, cluster).
250 251
        """
251 252

  
252
        q = ("select serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster "
253
        q = ("select serial, node, hash, size, type, source, mtime, muser, "
254
             "uuid, checksum, cluster "
253 255
             "from versions "
254 256
             "where node = ?")
255 257
        self.execute(q, (node,))
......
407 409
    def node_account_quotas(self):
408 410
        q = ("select n.path, p.value from nodes n, policy p "
409 411
             "where n.node != 0 and n.parent = 0 "
410
             "and n.node = p.node and p.key = 'quota'"
411
        )
412
             "and n.node = p.node and p.key = 'quota'")
412 413
        return dict(self.execute(q).fetchall())
413 414

  
414 415
    def node_account_usage(self, account_node, cluster):
415 416
        select_children = ("select node from nodes where parent = ?")
416 417
        select_descedents = ("select node from nodes "
417 418
                             "where parent in (%s) "
418
                             "or node in (%s) ") % ((select_children,)*2)
419
        args = [account_node]*2
419
                             "or node in (%s) ") % ((select_children,) * 2)
420
        args = [account_node] * 2
420 421
        q = ("select sum(v.size) from versions v, nodes n "
421 422
             "where v.node = n.node "
422 423
             "and n.node in (%s) "
......
454 455

  
455 456
        qs = ("select population, size from statistics "
456 457
              "where node = ? and cluster = ?")
457
        qu = ("insert or replace into statistics (node, population, size, mtime, cluster) "
458
        qu = ("insert or replace into statistics "
459
              "(node, population, size, mtime, cluster) "
458 460
              "values (?, ?, ?, ?, ?)")
459 461
        self.execute(qs, (node, cluster))
460 462
        r = self.fetchone()
......
505 507
        parent, path = props
506 508

  
507 509
        # The latest version.
508
        q = ("select serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster "
510
        q = ("select serial, node, hash, size, type, source, mtime, muser, "
511
             "uuid, checksum, cluster "
509 512
             "from versions v "
510 513
             "where serial = %s "
511 514
             "and cluster != ?")
......
568 571
           Return the (serial, mtime) of the new version.
569 572
        """
570 573

  
571
        q = ("insert into versions (node, hash, size, type, source, mtime, muser, uuid, checksum, cluster) "
574
        q = ("insert into versions (node, hash, size, type, source, mtime, "
575
             "muser, uuid, checksum, cluster) "
572 576
             "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
573 577
        mtime = time()
574 578
        props = (node, hash, size, type, source, mtime, muser,
......
598 602
        if not all_props:
599 603
            q = q % ("serial", subq)
600 604
        else:
601
            q = q % ("serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster", subq)
605
            q = q % (("serial, node, hash, size, type, source, mtime, muser, "
606
                      "uuid, checksum, cluster"),
607
                     subq)
602 608

  
603 609
        self.execute(q, args + [cluster])
604 610
        props = self.fetchone()
......
606 612
            return props
607 613
        return None
608 614

  
609
    def version_lookup_bulk(self, nodes, before=inf, cluster=0, all_props=True):
615
    def version_lookup_bulk(self, nodes, before=inf, cluster=0,
616
                            all_props=True):
610 617
        """Lookup the current versions of the given nodes.
611 618
           Return a list with their properties:
612
           (serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster).
619
           (serial, node, hash, size, type, source, mtime, muser, uuid,
620
            checksum, cluster).
613 621
        """
614 622

  
615 623
        if not nodes:
......
623 631
        if not all_props:
624 632
            q = q % ("serial", subq, '')
625 633
        else:
626
            q = q % ("serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster", subq, 'order by node')
634
            q = q % (("serial, node, hash, size, type, source, mtime, muser, "
635
                     "uuid, checksum, cluster"),
636
                     subq,
637
                     'order by node')
627 638

  
628 639
        args += [cluster]
629 640
        self.execute(q, args)
......
633 644
        """Return a sequence of values for the properties of
634 645
           the version specified by serial and the keys, in the order given.
635 646
           If keys is empty, return all properties in the order
636
           (serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster).
647
           (serial, node, hash, size, type, source, mtime, muser, uuid,
648
            checksum, cluster).
637 649
        """
638 650

  
639
        q = ("select serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster "
651
        q = ("select serial, node, hash, size, type, source, mtime, muser, "
652
             "uuid, checksum, cluster "
640 653
             "from versions "
641 654
             "where serial = ?")
642 655
        self.execute(q, (serial,))
......
702 715
        return hash, size
703 716

  
704 717
    def attribute_get(self, serial, domain, keys=()):
705
        """Return a list of (key, value) pairs of the version specified by serial.
718
        """Return a list of (key, value) pairs of the specific version.
719

  
706 720
           If keys is empty, return all attributes.
707 721
           Othwerise, return only those specified.
708 722
        """
......
714 728
                 "where key in (%s) and serial = ? and domain = ?" % (marks,))
715 729
            execute(q, keys + (serial, domain))
716 730
        else:
717
            q = "select key, value from attributes where serial = ? and domain = ?"
731
            q = ("select key, value from attributes where "
732
                 "serial = ? and domain = ?")
718 733
            execute(q, (serial, domain))
719 734
        return self.fetchall()
720 735

  
......
727 742
             "(serial, domain, node, is_latest, key, value) "
728 743
             "values (?, ?, ?, ?, ?, ?)")
729 744
        self.executemany(q, ((serial, domain, node, is_latest, k, v) for
730
            k, v in items))
745
                         k, v in items))
731 746

  
732 747
    def attribute_del(self, serial, domain, keys=()):
733 748
        """Delete attributes of the version specified by serial.
......
736 751
        """
737 752

  
738 753
        if keys:
739
            q = "delete from attributes where serial = ? and domain = ? and key = ?"
754
            q = ("delete from attributes "
755
                 "where serial = ? and domain = ? and key = ?")
740 756
            self.executemany(q, ((serial, domain, key) for key in keys))
741 757
        else:
742 758
            q = "delete from attributes where serial = ? and domain = ?"
......
763 779
        args = []
764 780

  
765 781
        if included:
766
            subq = "exists (select 1 from attributes where serial = v.serial and domain = ? and "
782
            subq = ("exists (select 1 from attributes where serial = v.serial "
783
                    "and domain = ? and ")
767 784
            subq += "(" + ' or '.join(('key = ?' for x in included)) + ")"
768 785
            subq += ")"
769 786
            args += [domain]
......
771 788
            append(subq)
772 789

  
773 790
        if excluded:
774
            subq = "not exists (select 1 from attributes where serial = v.serial and domain = ? and "
791
            subq = ("not exists (select 1 from attributes where "
792
                    "serial = v.serial and domain = ? and ")
775 793
            subq += "(" + ' or '.join(('key = ?' for x in excluded)) + ")"
776 794
            subq += ")"
777 795
            args += [domain]
......
780 798

  
781 799
        if opers:
782 800
            for k, o, v in opers:
783
                subq = "exists (select 1 from attributes where serial = v.serial and domain = ? and "
801
                subq = ("exists (select 1 from attributes where "
802
                        "serial = v.serial and domain = ? and ")
784 803
                subq += "key = ? and value %s ?" % (o,)
785 804
                subq += ")"
786 805
                args += [domain, k, v]
......
874 893
            args += [before]
875 894
        return q % where_cond, args
876 895

  
877
    def latest_attribute_keys(self, parent, domain, before=inf, except_cluster=0, pathq=None):
896
    def latest_attribute_keys(self, parent, domain, before=inf,
897
                              except_cluster=0, pathq=None):
878 898
        """Return a list with all keys pairs defined
879 899
           for all latest versions under parent that
880 900
           do not belong to the cluster.
......
955 975

  
956 976
           Limit applies to the first list of tuples returned.
957 977

  
958
           If all_props is True, return all properties after path, not just serial.
978
           If all_props is True, return all properties after path,
979
           not just serial.
959 980
        """
960 981

  
961 982
        execute = self.execute
......
978 999
        if not all_props:
979 1000
            q = q % ("v.serial", subq)
980 1001
        else:
981
            q = q % ("v.serial, v.node, v.hash, v.size, v.type, v.source, v.mtime, v.muser, v.uuid, v.checksum, v.cluster", subq)
1002
            q = q % (("v.serial, v.node, v.hash, v.size, v.type, v.source, "
1003
                      "v.mtime, v.muser, v.uuid, v.checksum, v.cluster"),
1004
                     subq)
982 1005
        args += [except_cluster, parent, start, nextling]
983 1006
        start_index = len(args) - 2
984 1007

  
......
1020 1043
            if props is None:
1021 1044
                break
1022 1045
            path = props[0]
1023
            serial = props[1]
1024 1046
            idx = path.find(delimiter, pfz)
1025 1047

  
1026 1048
            if idx < 0:
......
1083 1105
             "n.path in (%s)") % ','.join('?' for _ in paths)
1084 1106
        args = [domain]
1085 1107
        map(args.append, paths)
1086
        if cluster != None:
1108
        if cluster is not None:
1087 1109
            q += "and v.cluster = ?"
1088 1110
            args += [cluster]
1089 1111

  
......
1091 1113
        rows = self.fetchall()
1092 1114

  
1093 1115
        group_by = itemgetter(slice(12))
1094
        rows.sort(key = group_by)
1116
        rows.sort(key=group_by)
1095 1117
        groups = groupby(rows, group_by)
1096
        return [(k[0], k[1:], dict([i[12:] for i in data])) \
1097
            for (k, data) in groups]
1118
        return [(k[0], k[1:], dict([i[12:] for i in data])) for
1119
                (k, data) in groups]

Also available in: Unified diff