~pjjw/cephfs-layout-tool

4b07aa12247e1dc23f26e85a76944870ab9462ea — peter woodman 4 years ago 7226991
add flake8 config
2 files changed, 26 insertions(+), 19 deletions(-)

A .flake8
M cephfs_layout_tool/migrate_pools.py
A .flake8 => .flake8 +2 -0
@@ 0,0 1,2 @@
[flake8]
max-line-length = 100

M cephfs_layout_tool/migrate_pools.py => cephfs_layout_tool/migrate_pools.py +24 -19
@@ 1,4 1,3 @@
#!/usr/bin/env python3
import os
import shutil
import sys


@@ 6,15 5,24 @@ import tempfile
import functools
import argparse

# from collections import namedtuple
from typing import Optional, NamedTuple

import xattr  # type: ignore
import humanize  # type: ignore

TMPDIR = "/c/tmp"

OK_POOLS = {"cephfs_crs52data", "cephfs_crs52data2"}
def memoize(obj):
    """Decorator to memoize a function."""
    cache = obj.cache = {}

    @functools.wraps(obj)
    def memoizer(*args, **kwargs):
        key = str(args) + str(kwargs)
        if key not in cache:
            cache[key] = obj(*args, **kwargs)
        return cache[key]

    return memoizer


class CephLayout(


@@ 28,18 36,12 @@ class CephLayout(
        )


def memoize(obj):
    """Decorator to memoize a function."""
    cache = obj.cache = {}
class LayoutFixer(object):
    def __init__(self):
        self.LayoutDirs = {}

    @functools.wraps(obj)
    def memoizer(*args, **kwargs):
        key = str(args) + str(kwargs)
        if key not in cache:
            cache[key] = obj(*args, **kwargs)
        return cache[key]

    return memoizer
    def fix_file_layout(self, file):
        pass


@memoize


@@ 71,7 73,7 @@ def extract_layout(filename: str) -> Optional[CephLayout]:

# make a temp dir with the same layout as the given dir
@memoize
def mkdtemp_layout(layout: CephLayout, prefix: str = TMPDIR) -> str:
def mkdtemp_layout(layout: CephLayout, prefix: str) -> str:
    """Create temporary directory with the given layout"""
    tempdir = tempfile.mkdtemp(dir=prefix)
    xattrs = xattr.xattr(tempdir)


@@ 82,14 84,17 @@ def mkdtemp_layout(layout: CephLayout, prefix: str = TMPDIR) -> str:

def main():
    """entrypoint of script"""
    parser = argparse.ArgumentParser(description="Ensure cephfs files match their directory layouts")
    parser.add_argument('dir', help="directory to scan")
    parser = argparse.ArgumentParser(
        description="Ensure cephfs files match their directory layouts"
    )
    parser.add_argument("dir", help="directory to scan")
    parser.add_argument("--tmpdir", default="/c/tmp", help="temporary directory to copy files to")
    args = parser.parse_args()

    total_savings = 0
    total_moved = 0

    session_tmpdir = tempfile.mkdtemp(dir=TMPDIR)
    session_tmpdir = tempfile.mkdtemp(dir=args.tmpdir)

    print("starting scan of {}".format(args.dir), file=sys.stderr)
    for root, _, files in os.walk(args.dir, topdown=False):