示例#1
0
文件: gitbib.py 项目: syvlo/GitBib
def delete(argv):
	if len(argv) == 0:
		print "You need to provide at least one reference name to delete"
		sys.exit(1)

	config = Config(CONFIG_FILE)
	filename = config.getBibLocation()
	Entries = getBibEntries(filename)

	IndexToModify = []
	ReferencesToFind = argv

	#Check that references are in the base
	countEntry = 0
	for entry in Entries:
		for ref in ReferencesToFind:
			if entry.getReference() == ref:
				IndexToModify.append(countEntry)
				ReferencesToFind.remove(ref)
		countEntry = countEntry + 1

	if len(ReferencesToFind) > 0:
		print "Some references were not found:"
		print ReferencesToFind
		sys.exit(1)

	with open(".gitbibtmp.bib", 'w') as f:
		for iEntry in range(len(Entries)):
			for iIndexToModify in IndexToModify:
				if iEntry == iIndexToModify:
					Entries[iEntry].removeFiles(config.getFilesLocation())
				else:
					f.write(str(Entries[iEntry]) + '\n')

	shutil.copy(".gitbibtmp.bib", filename)
示例#2
0
文件: gitbib.py 项目: syvlo/GitBib
def show(argv):
	if len(argv) == 0:
		print "You need to provide at least one reference name to show"
		sys.exit(1)

	config = Config(CONFIG_FILE)
	filename = config.getBibLocation()
	filespath = config.getFilesLocation()
	pdfViewer = config.getPDFViewer()
	Entries = getBibEntries(filename)

	for i in argv:
		Found = False
		for entry in Entries:
			if i == entry.getReference():
				Found = True
				Files = entry.getFiles().split(',')
				for File in Files:
					File = File.strip(' ')
					Ext = os.path.splitext(File)[1]
					if Ext.lower() == ".pdf":
						subprocess.Popen([pdfViewer, filespath+File])
					else:
						print "Cannot read " + File

		if Found == False:
			print "Could not find an entry named " + i
示例#3
0
文件: gitbib.py 项目: syvlo/GitBib
def add(argv):
	config = Config(CONFIG_FILE)
	filename = config.getBibLocation()
	try:
		f = open(filename, 'a')
		print "Bibtex entry (enter a blank line at the end of the input):"
		sentinel = ''
		bibtex = ''
		for line in iter(raw_input, sentinel):
			bibtex = bibtex + line + '\n'

		bibtexentry = BibTexEntry(bibtex)
		Entries = getBibEntries(filename)
		for entry in Entries:
			if entry.getReference() == bibtexentry.getReference():
				print bibtexentry.getReference() + " already exists in " + filename + "."
				print "Please remove or update existing entry"
				sys.exit(1)
		print "Category (select or enter a new one):"
		Categories = getCategories(Entries)
		if len(Categories) > 0:
			i = 0
			for cat in Categories:
				print str(i) + ": " + cat
				i = i + 1

		category = raw_input()
		if category.isdigit():
			category = Categories[int(category)]
		if category == '':
			category = "Uncategorized"

		bibtexentry.setCat(category)

		print "Related files:"
		files = raw_input()
		bibtexentry.setFiles(files, config.getFilesLocation())
		f.write(str(bibtexentry) + '\n')
		f.close()

		print "Entry added."
		bibtexentry.checkFields()
	except IOError:
		print "Error when appending to ", filename
示例#4
0
文件: gitbib.py 项目: syvlo/GitBib
def search(argv):
	if len(argv) < 2:
		print "Search needs at least one keyword..."
		sys.exit(1)

	config = Config(CONFIG_FILE)
	filename = config.getBibLocation()
	Entries = getBibEntries(filename)
	RankedEntries = []

	for entry in Entries:
		score = entry.search(argv[2:])
		if score > 0:
			RankedEntries.append((score, entry))

	RankedEntries.sort(key=lambda tup: tup[0])

	count = len(RankedEntries)
	if count == 0:
		print "No entry found matching search"
	for entry in RankedEntries:
		print "========== " + str(count) + " =========="
		print entry[1]
		count = count - 1