24 lines
847 B
Plaintext
24 lines
847 B
Plaintext
|
#!/usr/bin/env python3
|
||
|
|
||
|
import os
|
||
|
import argparse
|
||
|
|
||
|
parser = argparse.ArgumentParser(description="Place a folder in ~/Documents in ~/Documents/Archive and symlink it")
|
||
|
parser.add_argument('dir', metavar='DIRECTORY', type=str, help="The directory to archive")
|
||
|
args = parser.parse_args()
|
||
|
|
||
|
source = os.path.realpath(args.dir)
|
||
|
assert(os.path.isdir(source)), source + " must be a directory"
|
||
|
|
||
|
# Finding directories
|
||
|
assert('HOME' in os.environ), "Home directory unknown"
|
||
|
docs = os.path.realpath(os.path.join(os.environ['HOME'], 'Documents'))
|
||
|
assert(os.path.isdir(docs)), "Documents folder not found"
|
||
|
arcs = os.path.join(docs, 'Archives')
|
||
|
assert(os.path.isdir(arcs)), "Archives folder not found"
|
||
|
|
||
|
assert(source.startswith(docs)), "Directory is not in the document folder"
|
||
|
assert(not source.startswith(arcs)), "Directory is already in the archive folder"
|
||
|
|
||
|
|