Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/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.
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