From 2bad953855b6671aca348c46280b9a560af0f1b3 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Sun, 22 Oct 2017 19:43:33 +0300 Subject: [PATCH] config: copymode, local_copymode, copyrights --- pygnulib/config.py | 38 ++++++++++++++++++++ pygnulib/parser.py | 86 +++++++++++++++++++++------------------------- 2 files changed, 78 insertions(+), 46 deletions(-) diff --git a/pygnulib/config.py b/pygnulib/config.py index 7adaf23c6f..c47d995941 100644 --- a/pygnulib/config.py +++ b/pygnulib/config.py @@ -62,6 +62,8 @@ class Base: "modules" : set(), "avoid" : set(), "files" : set(), + "copymode" : None, + "local_copymode" : None, } _OPTIONS_ = frozenset({ "tests", @@ -81,6 +83,7 @@ class Base: Longrunning = (1 << 3) Privileged = (1 << 4) Unportable = (1 << 5) + Copyrights = (1 << 6) AllTests = (Obsolete | Tests | CXX | Longrunning | Privileged | Unportable) @@ -482,6 +485,41 @@ class Base: return "GL_{0}".format(prefix) if prefix == default else "GL" + @property + def copymode(self): + return self.__table["copymode"] + + @copymode.setter + def copymode(self, value): + if value not in frozenset({None, "symlink", "hardlink"}): + raise ValueError("copymode: None, 'symlink' or 'hardlink'") + self.__table["copymode"] = value + + + @property + def local_copymode(self): + return self.__table["local_copymode"] + + @local_copymode.setter + def local_copymode(self, value): + if value not in frozenset({None, "symlink", "hardlink"}): + raise ValueError("local_copymode: None, 'symlink' or 'hardlink'") + self.__table["local_copymode"] = value + + + @property + def copyrights(self): + return bool(self.__table["options"] & Base._Option_.Copyrights) + + @copyrights.setter + def copyrights(self, value): + _type_assert_("copyrights", value, bool) + if value: + self.__table["options"] |= Base._Option_.Copyrights + else: + self.__table["options"] &= ~Base._Option_.Copyrights + + def __getitem__(self, key): table = (set(Base._TABLE_.keys()) | Base._OPTIONS_) if key not in table: diff --git a/pygnulib/parser.py b/pygnulib/parser.py index a7b0791995..d5362b5104 100644 --- a/pygnulib/parser.py +++ b/pygnulib/parser.py @@ -211,30 +211,38 @@ class CommandLine: super().__call__(parser, namespace, value, option) - class _LinkOption_(_Option_): + class _CopyModeOption_(_Option_): def __init__(self, *args, **kwargs): super().__init__(nargs=0, *args, **kwargs) def __call__(self, parser, namespace, value, option=None): if not hasattr(namespace, self.dest): - setattr(namespace, self.dest, CommandLine._LINK_NOTICE_) - value = getattr(namespace, self.dest) - symlink = ("-s", "--symlink", "--local-symlink", "-S", "--more-symlink") - hardlink = ("-h", "--hardlink", "--local-hardlink", "-H", "--more-hardlink") - local = ("--local-symlink", "--local-hardlink") - disable_notice = ("-S", "--more-symlink", "-H", "--more-hardlink") - if option in symlink: - if value & CommandLine._LINK_HARD_: - parser.error("conflicting --symlink and --hardlink options") - value |= CommandLine._LINK_SYMBOLIC_ - if option in hardlink: - if value & CommandLine._LINK_SYMBOLIC_: - parser.error("conflicting --symlink and --hardlink options") - value |= CommandLine._LINK_HARD_ - if option in local: - value |= CommandLine._LINK_LOCAL_ - if option in disable_notice: - value &= ~CommandLine._LINK_NOTICE_ + setattr(namespace, self.dest, None) + if option.endswith("symlink"): + value = "symlink" + elif option.endswith("hardlink"): + value = "hardlink" + else: + fmt = "{}: None, 'symlink' or 'hardlink'" + raise ValueError(fmt.format(self.dest)) + super().__call__(parser, namespace, value, option) + + + class _CopyrightsCopyModeOption_(_CopyModeOption_): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def __call__(self, parser, namespace, value, option=None): + if not hasattr(namespace, self.dest): + setattr(namespace, "copyrights", False) + if option.endswith("symlink"): + value = "symlink" + elif option.endswith("hardlink"): + value = "hardlink" + else: + fmt = "{}: None, 'symlink' or 'hardlink'" + raise ValueError(fmt.format(self.dest)) + setattr(namespace, "copyrights", True) super().__call__(parser, namespace, value, option) @@ -778,31 +786,31 @@ class CommandLine: "help": ( "make symbolic links instead of copying files", ), - "action": _LinkOption_, - "dest": "link", + "action": _CopyModeOption_, + "dest": "copymode", }), (["--local-symlink"], { "help": ( "make symbolic links instead of copying files, only", "for files from the local override directory" ), - "action": _LinkOption_, - "dest": "link", + "action": _CopyModeOption_, + "dest": "local_copymode", }), (["-h", "--hardlink"], { "help": ( "make hard links instead of copying files", ), - "action": _LinkOption_, - "dest": "link", + "action": _CopyModeOption_, + "dest": "copymode", }), (["--local-hardlink"], { "help": ( "make hard links instead of copying files, only", "for files from the local override directory" ), - "action": _LinkOption_, - "dest": "link", + "action": _CopyModeOption_, + "dest": "local_copymode", }), ), ), @@ -817,16 +825,16 @@ class CommandLine: "make symbolic links instead of copying files and", "don't replace copyright notices", ), - "action": _LinkOption_, - "dest": "link", + "action": _CopyrightsCopyModeOption_, + "dest": "copymode", }), (["-H", "--more-hardlink"], { "help": ( "make symbolic links instead of copying files and", "don't replace copyright notices", ), - "action": _LinkOption_, - "dest": "link", + "action": _CopyrightsCopyModeOption_, + "dest": "copymode", }), ), ), @@ -882,11 +890,7 @@ class CommandLine: class Option: """option bitwise flags""" DryRun = (1 << 0) - Symlink = (1 << 1) - Hardlink = (1 << 2) - OnlyLocalLinks = (1 << 3) - UpdateCopyrights = (1 << 4) - SingleConfigure = (1 << 5) + SingleConfigure = (1 << 1) def __init__(self, program): @@ -944,16 +948,6 @@ class CommandLine: verbosity = namespace.pop("verbosity", 0) if namespace.pop("dry_run", False): options |= CommandLine.Option.DryRun - link = namespace.pop("link", None) - if link is not None: - if link & CommandLine._LINK_SYMBOLIC_: - options |= CommandLine.Option.Symlink - if link & CommandLine._LINK_HARD_: - options |= CommandLine.Option.Hardlink - if link & CommandLine._LINK_LOCAL_: - options |= CommandLine.Option.OnlyLocalLinks - if link & CommandLine._LINK_NOTICE_: - options |= CommandLine.Option.UpdateCopyrights if namespace.pop("single_configure", False): options |= CommandLine.Option.SingleConfigure namespace.pop("no_changelog", None) -- 2.39.5