Last active
May 11, 2016 10:09
-
-
Save rhattersley/406fc67f540fb7a239b8a88672b529e8 to your computer and use it in GitHub Desktop.
Recipe for creating iris-grib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Recipe to initialise iris-grib repo" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Cloning into 'iris-grib'...\n", | |
"remote: Counting objects: 37557, done.\u001b[K\n", | |
"remote: Compressing objects: 100% (5/5), done.\u001b[K\n", | |
"remote: Total 37557 (delta 1), reused 0 (delta 0), pack-reused 37551\u001b[K\n", | |
"Receiving objects: 100% (37557/37557), 97.80 MiB | 1.15 MiB/s, done.\n", | |
"Resolving deltas: 100% (26013/26013), done.\n", | |
"Checking connectivity... done.\n" | |
] | |
} | |
], | |
"source": [ | |
"!git clone git@github.com:SciTools/iris.git iris-grib" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"/home/richard/git/iris-grib\n" | |
] | |
} | |
], | |
"source": [ | |
"cd iris-grib" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Remove all the files that don't contain \"grib\"\n", | |
"\n", | |
"Also keep the licence definition files." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"1595\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"['test_um_to_pp.py',\n", | |
" 'PuRd_09.txt',\n", | |
" '_constraints.py',\n", | |
" 'test_std_names.py',\n", | |
" 'simple5_midpoint.cml']" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"grib_names = !git ls-files | grep grib | xargs -n 1 basename\n", | |
"all_names = !git ls-files | xargs -n 1 basename\n", | |
"dross_names = set(all_names) - set(grib_names) - set(['COPYING', 'COPYING.LESSER'])\n", | |
"\n", | |
"print len(dross_names)\n", | |
"list(dross_names)[:5]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"import subprocess\n", | |
"BFG_PATH = '/home/richard/Downloads/bfg-1.12.12.jar'\n", | |
"dross = ','.join(list(dross_names)[:])\n", | |
"arg = '{' + dross + '}'\n", | |
"subprocess.check_call(['java', '-jar', BFG_PATH, '--no-blob-protection', '--delete-files', arg])" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Remove irrelevant directories" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"dir_names = ['tools', 'docs', 'analysis', 'experimental', 'io', 'runner',\n", | |
" 'concatenate', 'plot', 'format_interop', '_pyke_rules', 'um',\n", | |
" 'cf', 'pp', 'ff', 'quickplot', 'aux_factory', 'netcdf',\n", | |
" 'name_loaders', 'abf', 'pp_rules', 'nimrod_load_rules',\n", | |
" 'pyke_rules', 'coords', 'cube', 'coord_systems', 'util'\n", | |
" 'coord_categorisation', 'merge', 'system', 'name_grib',\n", | |
" 'cdm', 'COLPEX', 'coord_api', 'FF', 'regrid', 'trajectory',\n", | |
" 'trui', 'usecases', 'xml']\n", | |
"arg = '{' + ','.join(dir_names) + '}'\n", | |
"subprocess.check_call(['java', '-jar', BFG_PATH, '--no-blob-protection', '--delete-folders', arg])" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Clean out redundant commits" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Writing rewrite_parents.rb\n" | |
] | |
} | |
], | |
"source": [ | |
"%%writefile rewrite_parents.rb\n", | |
"#!/usr/bin/ruby \n", | |
"old_parents = gets.chomp.gsub('-p ', ' ') \n", | |
"\n", | |
"if old_parents.empty? then \n", | |
" new_parents = [] \n", | |
"else \n", | |
" new_parents = `git show-branch --independent #{old_parents}`.split \n", | |
"end \n", | |
"\n", | |
"puts new_parents.map{|p| '-p ' + p}.join(' ')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"!chmod u+x rewrite_parents.rb" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"!git reset HEAD\n", | |
"pruned = !git filter-branch -f --prune-empty --parent-filter `readlink -f rewrite_parents.rb` -- --all" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Tidy up" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"!git reflog expire --expire=now --all" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Counting objects: 10922, done.\n", | |
"Delta compression using up to 2 threads.\n", | |
"Compressing objects: 100% (9823/9823), done.\n", | |
"Writing objects: 100% (10922/10922), done.\n", | |
"Total 10922 (delta 5685), reused 521 (delta 0)\n" | |
] | |
} | |
], | |
"source": [ | |
"!git gc --prune=now --aggressive" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"cleaned = !git clean -fdx" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.11" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment