39 lines
858 B
Python
39 lines
858 B
Python
import sys
|
|
from libwyag import repository, objects
|
|
from libwyag.parsers import argparser
|
|
|
|
|
|
def main(argv=sys.argv[1:]):
|
|
args = argparser.parse_args(argv)
|
|
|
|
if args.command == "init":
|
|
cmd_init(args)
|
|
elif args.command == "cat-file":
|
|
cmd_cat_file(args)
|
|
|
|
|
|
def cmd_init(args):
|
|
repository.create_repo(args.path)
|
|
|
|
|
|
def cmd_cat_file(args):
|
|
repo = repository.repo_find()
|
|
cat_file(repo, args.object, fmt=args.type.encode())
|
|
|
|
|
|
def cat_file(repo, obj, fmt=None):
|
|
obj = objects.read_object(repo, objects.find_object(repo, obj, fmt=fmt))
|
|
sys.stdout.buffer.write(obj.serialize())
|
|
|
|
|
|
def cmd_hash_object(args):
|
|
if args.write:
|
|
repo = repository.GitRepository(".")
|
|
else:
|
|
repo = None
|
|
|
|
with open(args.path, "rb") as fd:
|
|
sha = objects.hash_object(fd, args.type.encode(), repo)
|
|
print(sha)
|
|
|