Add option to use etag instead of date for extraction hierarchy.
This commit is contained in:
parent
b7729150ba
commit
df7bc9bc61
19
extract-crx
19
extract-crx
|
@ -25,7 +25,7 @@ import tarfile
|
||||||
import datetime
|
import datetime
|
||||||
import dateutil
|
import dateutil
|
||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
from ExtensionCrawler.archive import last_crx, get_local_archive_dir
|
from ExtensionCrawler.archive import last_crx, get_local_archive_dir, last_etag
|
||||||
|
|
||||||
# Script should run with python 3.4 or 3.5
|
# Script should run with python 3.4 or 3.5
|
||||||
assert sys.version_info >= (3, 4) and sys.version_info < (3, 6)
|
assert sys.version_info >= (3, 4) and sys.version_info < (3, 6)
|
||||||
|
@ -41,12 +41,16 @@ def helpmsg():
|
||||||
print(" -a=<DIR> archive directory")
|
print(" -a=<DIR> archive directory")
|
||||||
|
|
||||||
|
|
||||||
def get_tarinfo(members, name, winfs = False):
|
def get_tarinfo(members, name, winfs = False, etag = None):
|
||||||
"""Select tarinfo object with a specified path/name."""
|
"""Select tarinfo object with a specified path/name."""
|
||||||
for tarinfo in members:
|
for tarinfo in members:
|
||||||
if tarinfo.name == name:
|
if tarinfo.name == name:
|
||||||
if winfs:
|
if winfs:
|
||||||
tarinfo.name = name.replace(":","-")
|
tarinfo.name = name.replace(":","-")
|
||||||
|
if etag is not None:
|
||||||
|
(path, crx) = os.path.split(tarinfo.name)
|
||||||
|
(path, _) = os.path.split(path)
|
||||||
|
tarinfo.name = os.path.join(path,etag,crx)
|
||||||
yield tarinfo
|
yield tarinfo
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,10 +61,11 @@ def main(argv):
|
||||||
verbose = True
|
verbose = True
|
||||||
date = None
|
date = None
|
||||||
extid = ""
|
extid = ""
|
||||||
|
useetag = False
|
||||||
output = ""
|
output = ""
|
||||||
winfs = False
|
winfs = False
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(argv, "hsd:a:o:w", ["date=", "archive=", "output="])
|
opts, args = getopt.getopt(argv, "hsed:a:o:w", ["date=", "archive=", "output="])
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
helpmsg()
|
helpmsg()
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
@ -76,6 +81,8 @@ def main(argv):
|
||||||
output = arg
|
output = arg
|
||||||
elif opt in ("-w", "--winfs"):
|
elif opt in ("-w", "--winfs"):
|
||||||
winfs = True
|
winfs = True
|
||||||
|
elif opt in ("-e", "--etag"):
|
||||||
|
useetag = True
|
||||||
elif opt == '-s':
|
elif opt == '-s':
|
||||||
verbose = False
|
verbose = False
|
||||||
|
|
||||||
|
@ -93,6 +100,10 @@ def main(argv):
|
||||||
else:
|
else:
|
||||||
last = last_crx(os.path.join(basedir, "data"), extid)
|
last = last_crx(os.path.join(basedir, "data"), extid)
|
||||||
|
|
||||||
|
if useetag:
|
||||||
|
etag = last_etag(os.path.join(basedir, "data"), extid, last)
|
||||||
|
else:
|
||||||
|
etag = None
|
||||||
if last != "":
|
if last != "":
|
||||||
tar = os.path.join(basedir, "data",
|
tar = os.path.join(basedir, "data",
|
||||||
get_local_archive_dir(extid), extid + ".tar")
|
get_local_archive_dir(extid), extid + ".tar")
|
||||||
|
@ -100,7 +111,7 @@ def main(argv):
|
||||||
if verbose:
|
if verbose:
|
||||||
print("Extracting "+os.path.join(output, last))
|
print("Extracting "+os.path.join(output, last))
|
||||||
with tarfile.open(tar, 'r') as archive:
|
with tarfile.open(tar, 'r') as archive:
|
||||||
archive.extractall(path=output, members=get_tarinfo(archive, last, winfs))
|
archive.extractall(path=output, members=get_tarinfo(archive, last, winfs, etag))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main(sys.argv[1:])
|
main(sys.argv[1:])
|
||||||
|
|
Loading…
Reference in New Issue