Created
April 5, 2011 21:09
-
-
Save yevgenko/904560 to your computer and use it in GitHub Desktop.
Helper command that opening _utils page of desktopcouch
This file contains 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/python | |
# Copyright 2011 @Yeevgen | |
# Licensed under the Apache License, Version 2.0 | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
import os | |
import os.path | |
import re | |
import webbrowser | |
try: | |
import desktopcouch | |
except ImportError: | |
desktopcouch = None | |
""" | |
Helper command that opens _utils page of desktopcouch | |
put this file into your ~/bin directory and add following alias: | |
alias desktopcouch='python ~/bin/desktopcouch-cli.py' | |
""" | |
# Define a main() function | |
def main(): | |
if not desktopcouch: | |
raise Exception("Desktopcouch isn't available on this machine.") | |
ctx = desktopcouch.local_files.DEFAULT_CONTEXT | |
bookmark_file = os.path.join(ctx.db_dir, "couchdb.html") | |
try: | |
username, password = re.findall("<!-- !!([^!]+)!!([^!]+)!! -->", | |
open(bookmark_file).read())[-1] | |
except ValueError: | |
raise IOError("Bookmark file is corrupt."+ | |
"Username/password are missing.") | |
url = "http://%s:%s@localhost:%s/_utils" % (username, password, | |
desktopcouch.find_port()) | |
webbrowser.open_new_tab(url) | |
# This is the standard boilerplate that calls the main() function. | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment