Skip to content

Instantly share code, notes, and snippets.

@exaos
Created May 20, 2015 07:51
Show Gist options
  • Save exaos/0b739fb25479ac517f41 to your computer and use it in GitHub Desktop.
Save exaos/0b739fb25479ac517f41 to your computer and use it in GitHub Desktop.
Geant4 Fetcher
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@Exaos
'''
import os
import os.path as path
import yaml
import subprocess as sp
from pprint import pprint
def fetch_file(url, fn, cwd='.'):
fetcher = [ "wget", "-c" ]
fetcher.extend(["-O", fn, url])
ret = sp.Popen(fetcher, cwd=cwd)
ret.wait()
if ret.returncode: return False
return True
usage = """Usage: %s [command] [geant4-version]
commands:
list -- list versions
get [ver] -- fetch geant4 source of version [ver]
get-data [ver] -- fetch data needed by version [ver]
"""
if __name__=="__main__":
import sys
if len(sys.argv)<2:
print( usage%(sys.argv[0]) )
exit(0)
g4vers = yaml.load(open("versions.yaml"))
comm = g4vers.pop("common")
if sys.argv[1] == 'list':
pprint(g4vers.keys())
elif sys.argv[1] == 'get' and len(sys.argv)>2:
for v in sys.argv[2:]:
if v not in g4vers: continue
fmt = g4vers[v]['format'] if 'format' in g4vers[v] else 'tar.gz'
fn = "geant4.%s.%s"%(v, fmt)
url = "%s/%s"%(comm['base_url'],fn)
print url, fn
fetch_file(url, fn, cwd=os.getcwd())
elif sys.argv[1] == 'get-data' and len(sys.argv)>2:
for v in sys.argv[2:]:
for k in g4vers[v]['data']:
fn = "%s.%s.tar.gz"%(k, str(g4vers[v]['data'][k]))
url = "%s/%s"%(comm['base_url'],fn)
fetch_file(url, fn, cwd=os.getcwd())
else:
print( usage%(sys.argv[0]) )
common:
download_page: http://www.geant4.org/geant4/support/download.shtml
base_url: http://www.geant4.org/geant4/support/source
data:
lend: ftp://gdo-nuclear.ucllnl.org/pub/
G4LEND: ftp://gdo-nuclear.ucllnl.org/pub/G4LEND/
10.01.p01:
gcc: 4.2.1
clhep: 2.2.0.4
data:
G4NDL: 4.5
G4EMLOW: 6.41
G4PhotonEvaporation: 3.1
G4RadioactiveDecay: 4.2
G4SAIDDATA: 1.1
G4NEUTRONXS: 1.4
G4ABLA: 3.0
G4PII: 1.3
RealSurface: 1.0
G4ENSDFSTATE: 1.0
10.00.p04:
clhep: 2.1.4.1
data:
G4NDL: 4.4
G4EMLOW: 6.35
G4PhotonEvaporation: 3.0
G4RadioactiveDecay: 4.0
G4SAIDDATA: 1.1
G4NEUTRONXS: 1.4
G4ABLA: 3.0
G4PII: 1.3
RealSurface: 1.0
G4ENSDFSTATE: 1.0
9.6.p04:
gcc: 4.1.2
clhep: 2.1.3.1
data:
G4NDL: 4.2
G4EMLOW: 6.32
G4PhotonEvaporation: 2.3
G4RadioactiveDecay: 3.6
G4SAIDDATA: 1.1
G4NEUTRONXS: 1.2
G4ABLA: 3.0
G4PII: 1.3
RealSurface: 1.0
9.5.p02:
gcc: 4.1.2
clhep: 2.1.1.0
data:
G4NDL: 4.0
G4EMLOW: 6.23
G4PhotonEvaporation: 2.2
G4RadioactiveDecay: 3.4
G4ABLA: 3.0
G4NEUTRONXS: 1.1
G4PII: 1.3
RealSurface: 1.0
9.4.p04:
gcc: 4.1.2
clhep: 2.1.0.1
data:
G4NDL: 3.14, 0.2
G4EMLOW: 6.19
G4PhotonEvaporation: 2.1
G4RadioactiveDecay: 3.3
G4ABLA: 3.0
G4NEUTRONXS: 1.0
G4PII: 1.2
RealSurface: 1.0
9.3.p02:
gcc: 4.1.2
clhep: 2.0.4.5
data:
G4NDL: 3.13, 0.2
G4EMLOW: 6.9
PhotonEvaporation: 2.0
G4RadioactiveDecay: 3.2
G4ABLA: 3.0
RealSurface: 1.0
9.2.p04:
gcc: 3.4.6
clhep: 2.0.4.2
data:
G4NDL: 3.13, 0.2
G4EMLOW: 6.2
PhotonEvaporation: 2.0
G4RadioactiveDecay: 3.2
G4ABLA: 3.0
9.1.p04:
gcc: 3.4.6
clhep: 2.0.3.2
data:
G4NDL: 3.12, 0.2
G4EMLOW: 5.1
PhotonEvaporation: 2.0
G4RadioactiveDecay: 3.2
G4ABLA: 3.0
9.0.p02:
gcc: 3.4.6
clhep: 2.0.3.1
format: gtar.gz
data:
G4NDL: 3.11, 0.2
G4EMLOW: 4.3
PhotonEvaporation: 2.0
G4RadioactiveDecay: 3.2
8.3.p02:
gcc: 3.4.6
clhep: 2.0.3.1
format: gtar.gz
data:
G4NDL: 3.10, 0.2
G4EMLOW: 4.2
PhotonEvaporation: 2.0
G4RadioactiveDecay: 3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment