From a10f3274f16bf9b2b67e43763347b906e9c31834 Mon Sep 17 00:00:00 2001 From: Fabien Benureau Date: Thu, 4 Oct 2012 17:40:20 +0200 Subject: [PATCH] find, init, install cmds --- papers | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) mode change 100644 => 100755 papers diff --git a/papers b/papers old mode 100644 new mode 100755 index e69de29..6a14179 --- a/papers +++ b/papers @@ -0,0 +1,90 @@ +#!/usr/bin/env python + +import sys, os +import datetime +import shutil +import tempfile +import textwrap +from subprocess import call + +try: + import pybtex +except ImportError: + print '{}error{}: you need to install Pybtex; try running \'pip install pybtex\'.'.format(red, end) + + +# display + +bold = '\033[1m' +end = '\033[0m' + +black = '\033[0;30m' +red = '\033[0;31m' +green = '\033[0;32m' +yellow = '\033[0;33m' +blue = '\033[0;34m' +purple = '\033[0;35m' +cyan = '\033[0;36m' +grey = '\033[0;37m' + +# Bold +bblack = '\033[1;30m' +bred = '\033[1;31m' +bgreen = '\033[1;32m' +byellow = '\033[1;33m' +bblue = '\033[1;34m' +bpurple = '\033[1;35m' +bcyan = '\033[1;36m' +bgrey = '\033[1;37m' + + +# utility functions + +papersdir = None + +def find_papersdir(): + global papersdir + curdir = os.path.abspath(os.getcwd()) + while curdir != '': + if os.path.exists(curdir + '/.papers') and os.path.isdir(curdir + '/.papers'): + papersdir = curdir + '/.papers' + curdir = '' + if curdir == '/': + curdir = '' + else: + curdir = os.path.split(curdir)[0] + + if papersdir is None: + print '{}error{} : no papers repo found in this directory or in any parent directory.{}'.format(red, grey, end) + exit(0) + + +# commands + +def init_cmd(): + """Create a .papers directory""" + # create dir + papersdir = os.getcwd() + '/.papers' + if not os.path.exists(papersdir): + print '{}initializing papers in {}{}{}'.format(grey, cyan, papersdir, end) + os.makedirs(papersdir) + else: + print '{}error{} : papers already present in {}{}{}'.format(red, grey, cyan, papersdir, end) + +def install_cmd(): + """Install command on the system""" + print '{}file to install : {}{}{}'.format(grey, cyan, __file__, end) + default = '/usr/local/bin' + print "{}folder to install the papers command [{}{:s}{}] : {}".format(grey, cyan, default, grey, end), + sys.stdout.flush() + path = raw_input() + if path == '': + path = default + if not os.path.exists(path): + print "{}error{}: {}{:s}{} does not exist - installation aborted".format(red, end, cyan, path, end) + else: + if os.path.exists(path+'/papers'): + if os.path.samefile(path+'/papers', __file__): + return + shutil.copy(__file__, path) +