• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / ZODB / 5636305215

pending completion
5636305215

push

github

web-flow
Drop support for Python < 3.7 (#386)

* Bumped version for breaking release.

* Drop support for Python 2.7, 3.5, 3.6.

---------

Co-authored-by: Jens Vagelpohl <jens@plyp.com>

2877 of 4050 branches covered (71.04%)

554 of 554 new or added lines in 89 files covered. (100.0%)

13323 of 15914 relevant lines covered (83.72%)

0.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.58
/src/ZODB/scripts/migrateblobs.py
1
##############################################################################
2
#
3
# Copyright (c) 2008 Zope Foundation and Contributors.
4
# All Rights Reserved.
5
#
6
# This software is subject to the provisions of the Zope Public License,
7
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE
12
#
13
##############################################################################
14
"""A script to migrate a blob directory into a different layout.
1✔
15
"""
16

17
import logging
1✔
18
import optparse
1✔
19
import os
1✔
20
import shutil
1✔
21

22
from ZODB.blob import FilesystemHelper
1✔
23
from ZODB.utils import oid_repr
1✔
24

25

26
# Check if we actually have link
27
try:
1✔
28
    os.link
1✔
29
except AttributeError:
×
30
    link_or_copy = shutil.copy
×
31
else:
32
    def link_or_copy(f1, f2):
1✔
33
        try:
1✔
34
            os.link(f1, f2)
1✔
35
        except OSError:
×
36
            shutil.copy(f1, f2)
×
37

38

39
def migrate(source, dest, layout):
1✔
40
    source_fsh = FilesystemHelper(source)
1✔
41
    source_fsh.create()
1✔
42
    dest_fsh = FilesystemHelper(dest, layout)
1✔
43
    dest_fsh.create()
1✔
44
    print("Migrating blob data from `{}` ({}) to `{}` ({})".format(
1✔
45
        source, source_fsh.layout_name, dest, dest_fsh.layout_name))
46
    for oid, path in source_fsh.listOIDs():
1✔
47
        dest_path = dest_fsh.getPathForOID(oid, create=True)
1✔
48
        files = os.listdir(path)
1✔
49
        for file in files:
1✔
50
            source_file = os.path.join(path, file)
1✔
51
            dest_file = os.path.join(dest_path, file)
1✔
52
            link_or_copy(source_file, dest_file)
1✔
53
        print("\tOID: {} - {} files ".format(oid_repr(oid), len(files)))
1✔
54

55

56
def main(source=None, dest=None, layout="bushy"):
1✔
57
    usage = "usage: %prog [options] <source> <dest> <layout>"
×
58
    description = ("Create the new directory <dest> and migrate all blob "
×
59
                   "data <source> to <dest> while using the new <layout> for "
60
                   "<dest>")
61

62
    parser = optparse.OptionParser(usage=usage, description=description)
×
63
    parser.add_option("-l", "--layout",
×
64
                      default=layout, type='choice',
65
                      choices=['bushy', 'lawn'],
66
                      help="Define the layout to use for the new directory "
67
                      "(bushy or lawn). Default: %default")
68
    options, args = parser.parse_args()
×
69

70
    if not len(args) == 2:
×
71
        parser.error("source and destination must be given")
×
72

73
    logging.getLogger().addHandler(logging.StreamHandler())
×
74
    logging.getLogger().setLevel(0)
×
75

76
    source, dest = args
×
77
    migrate(source, dest, options.layout)
×
78

79

80
if __name__ == '__main__':
81
    main()
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc