comparison venv/lib/python2.7/site-packages/planemo/github_util.py @ 0:d67268158946 draft

planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author bcclaywell
date Mon, 12 Oct 2015 17:43:33 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d67268158946
1 """
2 """
3
4 try:
5 import github
6 has_github_lib = True
7 except ImportError:
8 github = None
9 has_github_lib = False
10
11 NO_GITHUB_DEP_ERROR = ("Cannot use github functionality - "
12 "PyGithub library not available.")
13
14
15 def get_github_config(ctx):
16 if "github" not in ctx.global_config:
17 return None
18 global_github_config = ctx.global_config["github"]
19 return GithubConfig(global_github_config)
20
21
22 class GithubConfig(object):
23
24 def __init__(self, config):
25 if not has_github_lib:
26 raise Exception(NO_GITHUB_DEP_ERROR)
27 self._github = github.Github(config["username"], config["password"])
28
29
30 def publish_as_gist_file(ctx, path, name="index"):
31 github_config = get_github_config(ctx)
32 user = github_config._github.get_user()
33 content = open(path, "r").read()
34 content_file = github.InputFileContent(content)
35 gist = user.create_gist(False, {name: content_file})
36 return gist.files[name].raw_url