~raharper/curtin/trunk.lvmroot

« back to all changes in this revision

Viewing changes to curtin/block/mkfs.py

  • Committer: Ryan Harper
  • Date: 2017-11-28 21:08:46 UTC
  • Revision ID: ryan.harper@canonical.com-20171128210846-k15q3rxtm7ktpzkn
Refactor mkfs parameter generation

Allow some mkfs parameters to accept a param formatter.  Some options like
'force' and 'quiet' are flag-only options which do not accept a param.
Those values don't need a tuple for their value, but just the flag string.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
}
65
65
 
66
66
family_flag_mappings = {
67
 
    "label": {"btrfs": "--label",
68
 
              "ext": "-L",
69
 
              "fat": "-n",
70
 
              "jfs": "-L",
71
 
              "ntfs": "--label",
72
 
              "reiserfs": "--label",
73
 
              "swap": "--label",
74
 
              "xfs": "-L"},
75
 
    "uuid": {"btrfs": "--uuid",
76
 
             "ext": "-U",
77
 
             "reiserfs": "--uuid",
78
 
             "swap": "--uuid",
79
 
             "xfs": "-m uuid=%s"},
 
67
    "fatsize": {"fat": ("-F", "{fatsize}")},
 
68
    # flag with no parameter
80
69
    "force": {"btrfs": "--force",
81
70
              "ext": "-F",
82
71
              "fat": "-I",
84
73
              "reiserfs": "-f",
85
74
              "swap": "--force",
86
75
              "xfs": "-f"},
87
 
    "fatsize": {"fat": "-F"},
 
76
    "label": {"btrfs": ("--label", "{label}"),
 
77
              "ext": ("-L", "{label}"),
 
78
              "fat": ("-n", "{label}"),
 
79
              "jfs": ("-L", "{label}"),
 
80
              "ntfs": ("--label", "{label}"),
 
81
              "reiserfs": ("--label", "{label}"),
 
82
              "swap": ("--label", "{label}"),
 
83
              "xfs": ("-L", "{label}")},
 
84
    # flag with no parameter, N.B: this isn't used/exposed
88
85
    "quiet": {"ext": "-q",
89
86
              "ntfs": "-q",
90
87
              "reiserfs": "-q",
91
88
              "xfs": "--quiet"},
92
89
    "sectorsize": {
93
 
        "btrfs": "--sectorsize",
94
 
        "ext": "-b",
95
 
        "fat": "-S",
96
 
        "xfs": "-s",
97
 
        "ntfs": "--sector-size",
98
 
        "reiserfs": "--block-size"}
 
90
        "btrfs": ("--sectorsize", "{sectorsize}",),
 
91
        "ext": ("-b", "{sectorsize}"),
 
92
        "fat": ("-S", "{sectorsize}"),
 
93
        "ntfs": ("--sector-size", "{sectorsize}"),
 
94
        "reiserfs": ("--block-size", "{sectorsize}"),
 
95
        "xfs": ("-s", "{sectorsize}")},
 
96
    "uuid": {"btrfs": ("--uuid", "{uuid}"),
 
97
             "ext": ("-U", "{uuid}"),
 
98
             "reiserfs": ("--uuid", "{uuid}"),
 
99
             "swap": ("--uuid", "{uuid}"),
 
100
             "xfs": ("-m uuid={uuid}",)},
99
101
}
100
102
 
101
103
release_flag_mapping_overrides = {
128
130
        if strict:
129
131
            raise ValueError("flag '%s' not supported by fs family '%s'" %
130
132
                             flag_name, fs_family)
131
 
    else:
132
 
        # xfs sets values via a param and key=value
133
 
        if ' ' in flag_sym:
134
 
            if param:
135
 
                flag_sym = flag_sym.replace('%s', param)
136
 
            ret.extend(flag_sym.split(' '))
137
133
        else:
138
 
            ret = [flag_sym]
139
 
            if param is not None:
140
 
                ret.append(param)
 
134
            return ret
 
135
 
 
136
    if param is None:
 
137
        ret.append(flag_sym)
 
138
    else:
 
139
        params = [k.format(**{flag_name: param}) for k in flag_sym]
 
140
        if list(params) == list(flag_sym):
 
141
            raise ValueError("Param %s not used for flag_name=%s and "
 
142
                             "fs_family=%s." % (param, flag_name, fs_family))
 
143
 
 
144
        ret.extend(params)
141
145
    return ret
142
146
 
143
147