Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
"""
Thin out old snapshots directories, so that after 6 months old, only one
per week is kept.
"""
import os
import re
import time
#!/bin/sh
#
# create a copy of the ESGF mirror site, consisting of hard links
#
# make it in a temporary location, and if it succeeds, rename it
# to a dated directory under the webserver (outside of the main tree)
#
# otherwise, leaves it in tmp location to be cleaned up next time
# this cron job runs.
#!/usr/bin/env python
"""
Generates an HTML file with a table listing the esg-node script versions
in each snapshot.
"""
import os
import glob
import re
@alaniwi
alaniwi / esgf_psql.py
Last active October 16, 2017 10:06
A convenience script to run psql with some variables set based on the esgf.properties
#!/usr/bin/env python
import os
import re
def read_properties(file="/esg/config/esgf.properties"):
"returns the esgf.properties as a dictionary"
d = {}
with open(file) as f:
for line in f.readlines():
@alaniwi
alaniwi / numfiles.py
Last active October 23, 2017 11:48
script to check for dataset with "number of files" inconsistency in ESGF index
#!/usr/bin/env python
import solr
import sys
"""
Identifies dataset in the Solr index for which the number_of_files in the
dataset record does not match the number of file records that reference
the dataset in the dataset_id of the file record.
@alaniwi
alaniwi / find_solr_invalid_timestamps.py
Created October 23, 2017 11:33
script to find Solr file docs with invalid timestamp
#!/usr/bin/env python
# Identifies the Solr file docs for which the timestamp has invalid format.
# before running this, ensure:
#
# - solrpy is available for import
#
# - solr has enough memory, e.g. in
# /usr/local/solr-home/master-8984/solr.in.sh
@alaniwi
alaniwi / ensure_myproxy_cert.py
Created March 4, 2018 13:26
Python code to ensure that a valid myproxy certificate exists (uses MyProxyClient)
import sys
import os
from cryptography import x509
from cryptography.hazmat.backends import default_backend
import datetime
from myproxy.client import MyProxyClient as MPC
from OpenSSL.SSL import Error as SSLError
"""
@alaniwi
alaniwi / test_cert.py
Created February 4, 2019 17:30
X509 certificate tester
from cryptography import x509
from cryptography.hazmat.backends import default_backend
import datetime
def cert_is_valid(cert_file, min_lifetime=0):
"""
Returns boolean - True if the certificate is in date.
Optional argument min_lifetime is the number of seconds
@alaniwi
alaniwi / get_ids_from_solr.py
Created February 11, 2019 10:48
Script to get a list of dataset IDs from the index node via the ESGF search.
"""
Gets a list of dataset IDs from the index node via the ESGF search.
"""
import requests
class GetSolrIDs(object):
def __init__(self,
url='https://c3s-models-index.ceda.ac.uk/esg-search/search/',
@alaniwi
alaniwi / get_fields_from_solr.py
Created February 12, 2019 06:49
Gets a list of dataset IDs and projects from the index node via the ESGF search.
"""
Gets a list of dataset IDs and projects from the index node via the ESGF search.
"""
import requests
class GetSolrIDs(object):
def __init__(self,
url='https://c3s-models-index.ceda.ac.uk/esg-search/search/',