-
Notifications
You must be signed in to change notification settings - Fork 21
/
pubGetSpringer
executable file
·97 lines (84 loc) · 3.49 KB
/
pubGetSpringer
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
#!/usr/bin/env python3
# first load the standard libraries from python
# we require at least python 2.5
#from sys import *
import sys
import logging, optparse, os, glob, tempfile, subprocess, shutil
import ftplib
from datetime import datetime
from os.path import *
# add <scriptDir>/lib/ to package search path
progFile = os.path.abspath(sys.argv[0])
progDir = os.path.dirname(progFile)
pubToolsLibDir = os.path.join(progDir, "lib")
sys.path.insert(0, pubToolsLibDir)
import pubGeneric, pubConf, maxXml, maxCommon
# === COMMAND LINE INTERFACE, OPTIONS AND HELP ===
parser = optparse.OptionParser("""usage: %prog [options] <outDir> - download newest updates from Springer FTP
Email [email protected] to get access.
The first chunk of big zips is shipped by mail on harddisks, updates are transferred by ftp.
This script handles only the updates.
""")
parser.add_option("-d", "--debug", dest="debug", action="store_true", help="show debug messages")
#parser.add_option("", "--parse", dest="parse", action="store_true", help="for debugging, just parse one single xml file", default=None)
parser.add_option("", "--auto", dest="auto", action="store_true", \
help="automatically set the output directory based on pubConf.textBaseDir")
(options, args) = parser.parse_args()
# ==== FUNCTIONs =====
#def downloadSpringer(user, password, outDir):
# ftpUrl, ftpDir = "ftp.springer-dds.com", "data/in"
# logging.debug("Connecting to %s, dir %s, user %s, password %s" % (ftpUrl, ftpDir, user, password))
# ftp = ftplib.FTP("ftp.springer-dds.com", user, password)
# ftp.cwd("/data/in")
# fileNames = ftp.nlst()
# logging.debug("Files on server: %s" % ",".join(fileNames))
#
# i = 0
# size = 0
# startTime = datetime.now()
# logFname = join(outDir, "updates.log")
# logFh = open(logFname, "w")
# for fileName in fileNames:
# locFileName = join(outDir, fileName)
# locTmpFile, locTmpFname = pubGeneric.makeTempFile("pubGetSpringer", ".zip")
# maxCommon.delOnExit(locTmpFname)
#
# logging.debug("Retrieving file %s to %s" % (fileName, locTmpFname))
# ftp.retrbinary('RETR %s' % fileName, locTmpFile.write)
# locTmpFile.flush()
# logging.debug("Moving file %s to %s" % (locTmpFname, locFileName))
# shutil.copy(locTmpFname, locFileName)
# locTmpFile.close()
# logging.debug("Deleting file %s on server" % (fileName))
# ftp.delete(fileName)
# logFh.write("\t".join([fileName, datetime.now().isoformat()]))
#
# i+=1
# size += getsize(locFileName)
#
# logFh.close()
# runtime = datetime.now() - startTime
# runSecs = runtime.seconds
# if i!=0:
# logging.info("Downloaded/removed %d files, total size %d, time %d seconds" % (i, size, runSecs))
# else:
# logging.info("No new springer updates to download.")
def downloadSpringer(user, password, outDir):
ftpUrl = "sftp://ftp.springernature.com"
logging.debug("Connecting to %s, user %s, password %s" % (ftpUrl, user, password))
cmd = ["lftp", "-q", "-u", user+","+password, ftpUrl, "-e", "mirror . "+outDir]
subprocess.call(cmd)
# ----------- MAIN --------------
# only for debugging
if args==[] and not options.auto:
parser.print_help()
exit(1)
pubGeneric.setupLogging(progFile, options)
#outDir = pubConf.consynDownloadDir
if options.auto:
outDir = join(pubConf.extDir, "springer", "updates")
else:
outDir = args[0]
user = pubConf.springerUser
password = pubConf.springerPass
downloadSpringer(user, password, outDir)