Archive / / archive.py
2009-05-18 16:38:34 UTC
previous next
#!/usr/bin/python3 -tt import sys import os cfg_archive_dir = "/home/shane/scratch/archivepy-test" cfg_output_dir = "/home/shane/scratch/archivepy-text/extracted" def print_help(): print("""Usage: archive.py [command] Commands: archive.py list List years currently in archive archive.py extract [year] Extract archive for [year] archive.py import [year] Import new or modified data for YEAR to created a new archive file (any preexisting archive file will be backed up beforehand) archive.py check-data Check archive files against checksums to ensure they have not be corrupted, then check any extracted content to ensure it matches the data in the archive files archive.py delete-output Delete extracted content of archive files Configured directories: Archive directory: {0} Output directory: {1}""".format(cfg_archive_dir, cfg_output_dir)) def list_years(): for file_ in os.listdir(cfg_archive_dir): try: file_parts = file_.split('.', 1) if len(file_parts) == 2 and file_parts[1] == 'tar.bz2': year = int(file_parts[0]) print(year) except ValueError: pass def extract_year(year): pass def import_year(year): pass def check_data(): pass def delete_output(): pass if __name__ == "__main__": if len(sys.argv) < 2: print_help() sys.exit() if sys.argv[1] == "list": if len(sys.argv) != 2: sys.exit("archive.py: list requires no arguments") list_years() elif sys.argv[1] == "extract": if len(sys.argv) != 3: sys.exit("archive.py: extract requires a year") extract_year(sys.argv[2]) elif sys.argv[1] == "import": if len(sys.argv) != 3: sys.exit("archive.py: import requires a year") import_year(sys.argv[2]) elif sys.argv[1] == "check-data": if len(sys.argv) != 2: sys.exit("archive.py: check-data requires no arguments") check_data() elif sys.argv[1] == "delete-output": if len(sys.argv) != 2: sys.exit("archive.py: delete-output requires no arguments") delete_output() else: sys.exit("archive.py: Invalid command")