from__future__importannotationsimportargparseimportenumimportosfromdataclassesimportdataclassfrompathlibimportPathfromtypingimportIterable,Set,UnionimporttomlCWD=Path.cwd()classVerbosity(enum.IntEnum):QUIET=0NORMAL=1VERBOSE=2VERY_VERBOSE=3@dataclassclassConfiguration:directories:Set[Path]include:Set[str]exclude:Set[str]remove_empty_directories:boolverbosity:Verbositydef__init__(self,directories:Iterable[Union[os.PathLike,str]]={CWD},include:Iterable[str]=set(),exclude:Iterable[str]=set(),remove_empty_directories:bool=False,quiet:bool=False,verbose:bool=False,very_verbose:bool=False,)->None:self.directories=set(map(lambdap:Path(p).resolve(),directories))self.include=set(include)self.exclude=set(exclude)self.remove_empty_directories=remove_empty_directoriesifquiet:self.verbosity=Verbosity.QUIETelifverbose:self.verbosity=Verbosity.VERBOSEelifvery_verbose:self.verbosity=Verbosity.VERY_VERBOSEelse:self.verbosity=Verbosity.NORMALdefparse_pyproject_toml()->dict:pyproject_toml=toml.load(CWD/"pyproject.toml")config:dict=pyproject_toml.get("tool",{}).get("dustpan",{})return{k.replace("-","_"):vfork,vinconfig.items()}defparse_arguments()->dict:parser=argparse.ArgumentParser(description="")parser.add_argument("directories",type=Path,nargs="+",help="Root directories to search")parser.add_argument("-p","--patterns",type=str,nargs="+",help="Additional path patterns to queue for removal")parser.add_argument("-i","--ignore",type=str,nargs="+",help="Path patterns to exclude from removal")parser.add_argument("--remove-empty-directories",action="store_true",help="Remove all childless directories")verbosity=parser.add_mutually_exclusive_group()verbosity.add_argument("-q","--quiet",action="store_true",help="Be quiet")verbosity.add_argument("-v","--verbose",action="store_true",help="Be more verbose")verbosity.add_argument("-vv","--very-verbose",action="store_true",help="Be very verbose")args=parser.parse_args()return{k:vfork,vinvars(args).items()ifbool(v)}CONFIG=Configuration(**{**parse_pyproject_toml(),**parse_arguments()})
defparse_arguments()->dict:parser=argparse.ArgumentParser(description="")parser.add_argument("directories",type=Path,nargs="+",help="Root directories to search")parser.add_argument("-p","--patterns",type=str,nargs="+",help="Additional path patterns to queue for removal")parser.add_argument("-i","--ignore",type=str,nargs="+",help="Path patterns to exclude from removal")parser.add_argument("--remove-empty-directories",action="store_true",help="Remove all childless directories")verbosity=parser.add_mutually_exclusive_group()verbosity.add_argument("-q","--quiet",action="store_true",help="Be quiet")verbosity.add_argument("-v","--verbose",action="store_true",help="Be more verbose")verbosity.add_argument("-vv","--very-verbose",action="store_true",help="Be very verbose")args=parser.parse_args()return{k:vfork,vinvars(args).items()ifbool(v)}
Return the integer represented by the given array of bytes.
bytes
Holds the array of bytes to convert. The argument must either
support the buffer protocol or be an iterable object producing bytes.
Bytes and bytearray are examples of built-in objects that support the
buffer protocol.
byteorder
The byte order used to represent the integer. If byteorder is 'big',
the most significant byte is at the beginning of the byte array. If
byteorder is 'little', the most significant byte is at the end of the
byte array. To request the native byte order of the host system, use
`sys.byteorder' as the byte order value. Default is to use 'big'.
signed
Indicates whether two's complement is used to represent the integer.
length
Length of bytes object to use. An OverflowError is raised if the
integer is not representable with the given number of bytes. Default
is length 1.
byteorder
The byte order used to represent the integer. If byteorder is 'big',
the most significant byte is at the beginning of the byte array. If
byteorder is 'little', the most significant byte is at the end of the
byte array. To request the native byte order of the host system, use
`sys.byteorder' as the byte order value. Default is to use 'big'.
signed
Determines whether two's complement is used to represent the integer.
If signed is False and a negative integer is given, an OverflowError
is raised.