2 # Copyright 2016-2020, Damian Johnson and The Tor Project
3 # See LICENSE for licensing information
6 Caches tor's latest fallback directories.
14 import stem
.util
.system
16 GITWEB_FALLBACK_LOG
= 'https://gitweb.torproject.org/tor.git/log/src/app/config/fallback_dirs.inc'
17 FALLBACK_DIR_LINK
= b
"href='/tor.git/commit/src/app/config/fallback_dirs.inc\\?id=([^']*)'"
19 if __name__
== '__main__':
21 fallback_dir_page
= urllib
.request
.urlopen(GITWEB_FALLBACK_LOG
).read()
22 fallback_dir_commit
= re
.search(FALLBACK_DIR_LINK
, fallback_dir_page
).group(1).decode('utf-8')
24 print("Unable to determine the latest commit to edit tor's fallback directories: %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 fallback directories: %s' % fallback_dir_commit
)
34 print('Current stem commit: %s' % stem_commit
)
37 cached_fallback_directories
= stem
.directory
.Fallback
.from_cache()
38 latest_fallback_directories
= stem
.directory
.Fallback
.from_remote()
40 if cached_fallback_directories
== latest_fallback_directories
:
41 print('Fallback directories are already up to date, nothing to do.')
44 # all fallbacks have the same header metadata, so just picking one
46 headers
= list(latest_fallback_directories
.values())[0].header
if latest_fallback_directories
else None
48 print('Differences detected...\n')
49 print(stem
.directory
._fallback
_directory
_differences
(cached_fallback_directories
, latest_fallback_directories
))
50 stem
.directory
.Fallback
._write
(latest_fallback_directories
, fallback_dir_commit
, stem_commit
, headers
)