2 # Copyright 2015-2020, Damian Johnson and The Tor Project
3 # See LICENSE for licensing information
6 Caches tor's latest manual content. Run this to pick new man page changes.
14 import stem
.util
.system
16 GITWEB_MAN_LOG
= 'https://gitweb.torproject.org/tor.git/log/doc/tor.1.txt'
17 MAN_LOG_LINK
= b
"href='/tor.git/commit/doc/tor.1.txt\\?id=([^']*)'"
19 if __name__
== '__main__':
21 man_log_page
= urllib
.request
.urlopen(GITWEB_MAN_LOG
).read()
22 man_commit
= re
.search(MAN_LOG_LINK
, man_log_page
).group(1).decode('utf-8')
24 print("Unable to determine the latest commit to edit tor's man page: %s" % sys
.exc_info()[1])
28 stem_commit
= stem
.util
.system
.call('git rev-parse HEAD')[0]
29 except OSError as exc
:
30 print("Unable to determine stem's current commit: %s" % exc
)
33 print('Latest tor commit editing man page: %s' % man_commit
)
34 print('Current stem commit: %s' % stem_commit
)
38 cached_manual
= stem
.manual
.Manual
.from_cache()
39 db_schema
= cached_manual
.schema
40 except stem
.manual
.SchemaMismatch
as exc
:
41 cached_manual
, db_schema
= None, exc
.database_schema
43 cached_manual
, db_schema
= None, None # local copy has been deleted
45 if db_schema
!= stem
.manual
.SCHEMA_VERSION
:
46 print('Cached database schema is out of date (was %s, but current version is %s)' % (db_schema
, stem
.manual
.SCHEMA_VERSION
))
49 latest_manual
= stem
.manual
.Manual
.from_remote()
52 if cached_manual
== latest_manual
:
53 print('Manual information is already up to date, nothing to do.')
56 print('Differences detected...\n')
57 print(stem
.manual
._manual
_differences
(cached_manual
, latest_manual
))
59 latest_manual
.man_commit
= man_commit
60 latest_manual
.stem_commit
= stem_commit
61 latest_manual
.save(stem
.manual
.CACHE_PATH
)