# There should be a file named `locations.json` in this setup where it contains a top-level hash map with the packages and their target path.
# Feel free to modify it accordingly.
# This script is tailored to my specific needs.
# It also strives to only rely on the standard library so further no installation needed.
# Feel free to modify this script as well.
# For future references, the Python version when creating for this script is v3.8.2.
# If there's any reason why stuff is not working, it might be because it is different on the older versions or just my bad code lol.
# Anyway, I feel like this script should be only up to half the size.
# Hell, I think this should be simpler but no... I pushed for a more complex setup or something.
# What am I doing?
# Is this what ricing is all about?
# Why are you reading this?
importargparse
importjson
importlogging
importos
importos.path
frompathlibimportPath
importsubprocess
importsys
PACKAGE_DATA_FILE="locations.json"
classPackageDir:
""" A package directory should have a file named `locations.json` where it contains a top-level object of the stow packages with their usual target path. """
argparser.add_argument("-c","--commands",metavar="command",help="Executing the specified commands. All of the commands are treated as they were entered in the shell.",nargs="*",default=["echo {package}"])
argparser.add_argument("-d","--directory",metavar="path",help="Set the directory of the package data file.",type=Path,nargs="?",default=Path(os.getcwd()))
argparser.add_argument("--exclude",metavar="package",help="Exclude the given packages.",type=str,nargs="+",default=[])
argparser.add_argument("--include",metavar=("package","location"),help="Include with the following packages.",type=str,nargs=2,action="append",default=[])
argparser.add_argument("--only",metavar="package",help="Only execute with the given packages.",type=str,nargs="+",default=[])
returnargparser
defparse_args(parser,argv):
"""
Parsethearguments.
Thisisalsothemainfunctiontopayattentionto.
:param:parser-Aninstanceoftheargumentparser.
:param:argv-Alistofargumentstobeparsed.
"""
args=parser.parse_args(argv)
try:
package_dir=PackageDir(args.directory)
# Include the following packages.
forpackage,targetinargs.include:
try:
package_dir.add_package(package,target)
exceptExceptionase:
logging.error(e)
# Exclude the following packages.
# We don't need the value here so we'll let it pass.