-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathgitberg
More file actions
executable file
·131 lines (102 loc) · 3.95 KB
/
Copy pathgitberg
File metadata and controls
executable file
·131 lines (102 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Usage:
gitberg config
gitberg library [status]
gitberg clone <book_repo_name>
gitberg (fetch | make | push | upload | metadata) <book_id> [options]
gitberg get <book_id> [options]
gitberg metadata <book_id> [options]
gitberg update [options]
gitberg report <book_identity>
gitberg all BOOKID BOOKIDEND [options]
gitberg list <book_id_list> [options]
gitberg apply <action> <book_repo_name>
Arguments:
<book_repo_name> -- The name of a repo in Gitenberg, `Frankenstein_84`
<target> -- a file path, example, where to clone a book
<action> -- action to apply to repo
Options:
-v --logging (debug | info | error)
--rdf_library <rdf_library> where are you storing rdf files
"""
# TODO use `--` to separate arguments and files
# ex: `git checkout -b foo -- file file1 file2
import logging
import sys
from docopt import docopt
from gitenberg import __version__
from gitenberg import Book
from gitenberg import clone
from gitenberg import config
from gitenberg import upload_all_books, upload_list
from gitenberg import library
from gitenberg import actions
def setup_logging(arguments):
""" creates a logger with our hard-coded configuration
takes: a docopt arguments object instance
"""
logger = logging.getLogger('')
logging.basicConfig(filename='./gitburg.log', level=logging.DEBUG)
#stdout_handler = logging.StreamHandler(sys.stdout)
#logger.addHandler(stdout_handler)
if ('--logging' or '-v') in arguments:
# if
log_level = arguments['--logging']
if log_level == 'debug':
logger.setLevel(logging.DEBUG)
elif log_level == 'info':
logger.setLevel(logging.INFO)
elif log_level == 'error':
logger.setLevel(logging.ERROR)
return logger
if __name__ == '__main__':
arguments = docopt(__doc__, version=__version__)
logger = setup_logging(arguments)
try:
if '--rdf_library' in arguments:
rdf_library = arguments['--rdf_library']
else:
rdf_library = config.data.get('rdf_library', None)
if arguments['<book_id>'] is not None:
book = Book(arguments['<book_id>'])
book.parse_book_metadata(rdf_library)
if arguments['fetch']:
logging.info("fetching a PG book: {0}".format(arguments['<book_id>']))
book.fetch()
elif arguments['make']:
logging.info("making a local git repo for: {0}".format(arguments['<book_id>']))
book.make()
elif arguments['push']:
logging.info("making a local git repo for: {0}".format(arguments['<book_id>']))
book.push()
elif arguments['upload']:
logging.info("making a local git repo for: {0}".format(arguments['<book_id>']))
book.push()
elif arguments['metadata']:
print book.meta.__unicode__()
elif arguments['all']:
upload_all_books(arguments['BOOKID'], arguments['BOOKIDEND'], rdf_library=rdf_library)
elif arguments['list']:
upload_list(arguments['<book_id_list>'], rdf_library=rdf_library)
elif arguments['config']:
config.check_config()
elif arguments['library']:
library()
elif arguments['update']:
raise NotImplementedError
elif arguments['report']:
raise NotImplementedError
elif arguments['clone']:
# TODO: check for stdin
arg_book_name = arguments['<book_repo_name>']
clone(arg_book_name)
elif arguments['apply']:
arg_book_name = arguments['<book_repo_name>']
arg_action = arguments['<action>']
action = getattr(actions, arg_action)
action(arg_book_name)
except config.NotConfigured as e:
print("\tGitberg needs configuration.")
config.check_config()