Last active
December 12, 2017 22:01
-
-
Save elfsternberg/dfaf8caae74a2e7bc3189f42426c358e to your computer and use it in GitHub Desktop.
A short script to walk a working projects directory and dump the "description" line from from all README files.
This file contains hidden or 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
#!/usr/bin/env python | |
# A small script that I use to keep track of what's currently in my "Projects" directory. | |
# Not a big deal, but maybe useful to someone. I have a fairly disciplined layout for | |
# my projects so this helps me keep track of my to-dos. | |
import os | |
PROJECTS = os.path.join(os.path.expanduser("~"), "Projects") | |
def walklevel(some_dir, level=1): | |
some_dir = some_dir.rstrip(os.path.sep) | |
assert os.path.isdir(some_dir) | |
num_sep = some_dir.count(os.path.sep) | |
for root, dirs, files in os.walk(some_dir): | |
yield root, dirs, files | |
num_sep_this = root.count(os.path.sep) | |
if num_sep + level <= num_sep_this: | |
del dirs[:] | |
def getdesc(fdir, fname): | |
with open(os.path.join(fdir, fname)) as f: | |
return f.readline().strip() | |
def pPath(fdir): | |
return ("/".join(fdir.split("/")[0:5])) | |
def pName(fdir): | |
return (fdir.split("/")[4]) | |
ret = [] | |
for dName, sdName, fList in walklevel(PROJECTS, 4): | |
for fName in fList: | |
if fName == 'DESCRIPTION.md': | |
ret.append((pPath(dName), pName(dName), getdesc(dName, fName))) | |
eDirs = [d for d in | |
[os.path.abspath(d) for d in os.listdir(PROJECTS) if os.path.isdir(d)] | |
if d not in [i[0] for i in ret]] | |
for i in eDirs: | |
ret.append((i, pName(i), "No description found.")) | |
ret = sorted(ret, key=lambda i: i[0]) | |
for r in ret: | |
print "{:18}: {}".format(r[1], r[2]) | |
# LICENSE: | |
# https://creativecommons.org/licenses/by/4.0/ | |
# | |
# This is free software released under the CC-BY license. Users of this software | |
# enjoy the following rights and responsibilities: | |
# | |
# Share — You may copy and redistribute the material in any medium or format | |
# Adapt — You may remix, transform, and build upon the material for any | |
# purpose, even commercially. | |
# | |
# Attribution — You must give appropriate credit, provide a link to the | |
# license, and indicate if changes were made. You may do so in any | |
# reasonable manner, but not in any way that suggests the licensor | |
# endorses you or your use. | |
# | |
# You may not employ technological measures or legal terms that legally | |
# prevent others from doing anything the license permits. | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY | |
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment