Skip to content

Instantly share code, notes, and snippets.

@he7d3r
Created December 4, 2014 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save he7d3r/c2e2ff4333d2996b16f5 to your computer and use it in GitHub Desktop.
Save he7d3r/c2e2ff4333d2996b16f5 to your computer and use it in GitHub Desktop.
Script to add a basic README.md file to many repositories in a directory
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright © 2014 He7d3r
# License: http://he7d3r.mit-license.org/
""" Script to add a basic README.md file to many repositories in a directory"""
import os
import sh
rootDir = '/home/username/GitHub/'
myFile = 'README.md'
prefix = 'mw-gadget-'
commitMessage = 'Add a README with installation instructions'
readme = """Installation
===========================
1. Go to one of the js subpages of your user page. You can choose a page such as these:
* [meta:User:`<Name>`/global.js](https://meta.wikimedia.org/wiki/Special:MyPage/global.js), which will be loaded in all wikis, in all skins
* [meta:User:`<Name>`/common.js](https://meta.wikimedia.org/wiki/Special:MyPage/common.js), which will be loaded only on Meta-wiki, in all skins
* [meta:User:`<Name>`/vector.js](https://meta.wikimedia.org/wiki/Special:MyPage/vector.js), which will be loaded only on Meta-wiki, in the vector skin
2. Copy the following to the page you have chosen:
```javascript
// [[File:User:He7d3r/Tools/{0}.js]] (workaround for [[bugzilla:33355]])
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=User:He7d3r/Tools/{0}.js&action=raw&ctype=text/javascript' );
```
3. Clear the cache of your browser.
This will import the minified copy of the script I maintain on Meta-wiki."""
def main(*args):
for repo in os.walk(rootDir).next()[1]:
readmePath = rootDir + repo + '/' + myFile
if not os.path.exists(readmePath):
print( repo )
f = open( readmePath, 'w' )
f.write( readme.format(repo[len(prefix):]).encode( 'utf8' ) )
f.close()
# Set up git
git = sh.git.bake( _cwd = rootDir + repo )
print(git.add( '--all' ))
print(git.commit( m = commitMessage ))
print(git.push())
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment