def on_done_password(self, value):
     "Callback for the password show_input_panel"
     self.github_password = value
     try:
         api = GitHubApi(self.base_uri, debug=self.debug)
         self.github_token = api.get_token(self.github_user,
                                           self.github_password,
                                           self.github_one_time_password)
         self.github_password = self.github_one_time_password = None  # don't keep these around
         self.accounts[self.active_account]["github_token"] = self.github_token
         self.settings.set("accounts", self.accounts)
         sublime.save_settings("GitHub.sublime-settings")
         self.gistapi = GitHubApi(self.base_uri, self.github_token, debug=self.debug)
         try:
             if self.callback:
                 sublime.error_message(self.MSG_TOKEN_SUCCESS)
                 callback = self.callback
                 self.callback = None
                 sublime.set_timeout(callback, 50)
         except AttributeError:
             pass
     except GitHubApi.OTPNeededException:
         sublime.set_timeout(self.get_one_time_password, 50)
     except GitHubApi.UnauthorizedException:
         sublime.error_message(self.ERR_UNAUTHORIZED)
         sublime.set_timeout(self.get_username, 50)
     except GitHubApi.UnknownException as e:
         sublime.error_message(e.message)
    def on_done_filename(self, value):
        self.filename = value
        # get selected text, or the whole file if nothing selected
        if all([region.empty() for region in self.view.sel()]):
            text = self.view.substr(sublime.Region(0, self.view.size()))
        else:
            text = "\n".join(
                [self.view.substr(region) for region in self.view.sel()])

        gistapi = GitHubApi(self.github_token, debug=self.debug)
        try:
            gist_url = gistapi.create_gist(description=self.description,
                                           filename=self.filename,
                                           content=text,
                                           public=self.public)
            sublime.set_clipboard(gist_url)
            sublime.status_message(self.MSG_SUCCESS)
        except GitHubApi.UnauthorizedException:
            # clear out the bad token so we can reset it
            self.settings.set("github_token", "")
            sublime.save_settings("GitHub.sublime-settings")
            sublime.error_message(self.ERR_UNAUTHORIZED_TOKEN)
            sublime.set_timeout(self.get_username, 50)
        except GitHubApi.UnknownException, e:
            sublime.error_message(e.message)
    def get_gists(self):
        self.gistapi = GitHubApi(self.github_token, debug=self.debug)
        try:
            self.gists = self.gistapi.list_gists(starred=self.starred)
            format = self.settings.get("gist_list_format")
            packed_gists = []
            for idx, gist in enumerate(self.gists):
                attribs = {
                    "index": idx + 1,
                    "filename": gist["files"].keys()[0],
                    "description": gist["description"] or ''
                }
                if isinstance(format, basestring):
                    item = format % attribs
                else:
                    item = [(format_str % attribs) for format_str in format]
                packed_gists.append(item)

            args = [packed_gists, self.on_done]
            if self.settings.get("gist_list_monospace"):
                args.append(sublime.MONOSPACE_FONT)
            self.view.window().show_quick_panel(*args)
        except GitHubApi.UnauthorizedException:
            sublime.error_message(self.ERR_UNAUTHORIZED_TOKEN)
            sublime.set_timeout(self.get_username, 50)
        except GitHubApi.UnknownException, e:
            sublime.error_message(e.message)
 def update(self):
     text = self.view.substr(sublime.Region(0, self.view.size()))
     gistapi = GitHubApi(self.github_token, debug=self.debug)
     try:
         gist_url = gistapi.update_gist(self.gist, text)
         sublime.set_clipboard(gist_url)
         sublime.status_message(self.MSG_SUCCESS)
     except GitHubApi.UnauthorizedException:
         # clear out the bad token so we can reset it
         self.settings.set("github_token", "")
         sublime.save_settings("GitHub.sublime-settings")
         sublime.error_message(self.ERR_UNAUTHORIZED_TOKEN)
         sublime.set_timeout(self.get_username, 50)
     except GitHubApi.UnknownException, e:
         sublime.error_message(e.message)
 def update(self):
     text = self.view.substr(sublime.Region(0, self.view.size()))
     gistapi = GitHubApi(self.github_token, debug=self.debug)
     try:
         gist_url = gistapi.update_gist(self.gist, text)
         sublime.set_clipboard(gist_url)
         sublime.status_message(self.MSG_SUCCESS)
     except GitHubApi.UnauthorizedException:
         # clear out the bad token so we can reset it
         self.settings.set("github_token", "")
         sublime.save_settings("GitHub.sublime-settings")
         sublime.error_message(self.ERR_UNAUTHORIZED_TOKEN)
         sublime.set_timeout(self.get_username, 50)
     except GitHubApi.UnknownException, e:
         sublime.error_message(e.message)
    def run(self, edit):
        self.settings = sublime.load_settings("GitHub.sublime-settings")
        self.github_user = None
        self.github_password = None
        self.github_one_time_password = None
        self.accounts = self.settings.get("accounts")
        self.active_account = self.settings.get("active_account")
        if not self.active_account:
            self.active_account = list(self.accounts.keys())[0]
        self.github_token = self.accounts[self.active_account]["github_token"]
        if not self.github_token:
            self.github_token = self.settings.get("github_token")
            if self.github_token:
                # migrate to new structure
                self.settings.set("accounts", {"GitHub": {"base_uri": "https://api.github.com", "github_token": self.github_token}})
                self.settings.set("active_account", "GitHub")
                self.active_account = self.settings.get("active_account")
                self.settings.erase("github_token")
                sublime.save_settings("GitHub.sublime-settings")
        self.base_uri = self.accounts[self.active_account]["base_uri"]
        self.debug = self.settings.get('debug')

        self.proxies = {'https': self.accounts[self.active_account].get("https_proxy", None)}
        self.force_curl = self.accounts[self.active_account].get("force_curl", False)
        self.gistapi = GitHubApi(self.base_uri, self.github_token, debug=self.debug,
                                 proxies=self.proxies, force_curl=self.force_curl)
Beispiel #7
0
 def run(self, edit):
     self.settings = sublime.load_settings("GitHub.sublime-settings")
     self.github_user = None
     self.accounts = self.settings.get("accounts")
     self.active_account = self.settings.get("active_account")
     if not self.active_account:
         self.active_account = self.accounts.keys()[0]
     self.github_token = self.accounts[self.active_account]["github_token"]
     if not self.github_token:
         self.github_token = self.settings.get("github_token")
         if self.github_token:
             # migrate to new structure
             self.settings.set(
                 "accounts", {
                     "GitHub": {
                         "base_uri": "https://api.github.com",
                         "github_token": self.github_token
                     }
                 })
             self.settings.set("active_account", "GitHub")
             self.active_account = self.settings.get("active_account")
             self.settings.erase("github_token")
             sublime.save_settings("GitHub.sublime-settings")
     self.base_uri = self.accounts[self.active_account]["base_uri"]
     self.debug = self.settings.get('debug')
     self.gistapi = GitHubApi(self.base_uri,
                              self.github_token,
                              debug=self.debug)
    def get_gists(self):
        self.gistapi = GitHubApi(self.github_token, debug=self.debug)
        try:
            self.gists = self.gistapi.list_gists(starred=self.starred)
            format = self.settings.get("gist_list_format")
            packed_gists = []
            for idx, gist in enumerate(self.gists):
                attribs = {"index": idx + 1,
                           "filename": gist["files"].keys()[0],
                           "description": gist["description"] or ''}
                if isinstance(format, basestring):
                    item = format % attribs
                else:
                    item = [(format_str % attribs) for format_str in format]
                packed_gists.append(item)

            args = [packed_gists, self.on_done]
            if self.settings.get("gist_list_monospace"):
                args.append(sublime.MONOSPACE_FONT)
            self.view.window().show_quick_panel(*args)
        except GitHubApi.UnauthorizedException:
            sublime.error_message(self.ERR_UNAUTHORIZED_TOKEN)
            sublime.set_timeout(self.get_username, 50)
        except GitHubApi.UnknownException, e:
            sublime.error_message(e.message)
    def on_done_filename(self, value):
        self.filename = value
        # get selected text, or the whole file if nothing selected
        if all([region.empty() for region in self.view.sel()]):
            text = self.view.substr(sublime.Region(0, self.view.size()))
        else:
            text = "\n".join([self.view.substr(region) for region in self.view.sel()])

        gistapi = GitHubApi(self.github_token, debug=self.debug)
        try:
            gist_url = gistapi.create_gist(description=self.description,
                                           filename=self.filename,
                                           content=text,
                                           public=self.public)
            sublime.set_clipboard(gist_url)
            sublime.status_message(self.MSG_SUCCESS)
        except GitHubApi.UnauthorizedException:
            # clear out the bad token so we can reset it
            self.settings.set("github_token", "")
            sublime.save_settings("GitHub.sublime-settings")
            sublime.error_message(self.ERR_UNAUTHORIZED_TOKEN)
            sublime.set_timeout(self.get_username, 50)
        except GitHubApi.UnknownException, e:
            sublime.error_message(e.message)
 def on_done_password(self, value):
     "Callback for the password show_input_panel"
     try:
         self.github_token = GitHubApi.get_token(self.github_user, value)
         self.settings.set("github_token", self.github_token)
         sublime.save_settings("GitHub.sublime-settings")
         if self.callback:
             sublime.error_message(self.MSG_TOKEN_SUCCESS)
             callback = self.callback
             self.callback = None
             sublime.set_timeout(callback, 50)
     except GitHubApi.UnauthorizedException:
         sublime.error_message(self.ERR_UNAUTHORIZED)
         sublime.set_timeout(self.get_username, 50)
     except GitHubApi.UnknownException, e:
         sublime.error_message(e.message)
 def on_done_password(self, value):
     "Callback for the password show_input_panel"
     try:
         self.github_token = GitHubApi.get_token(self.github_user, value)
         self.settings.set("github_token", self.github_token)
         sublime.save_settings("GitHub.sublime-settings")
         if self.callback:
             sublime.error_message(self.MSG_TOKEN_SUCCESS)
             callback = self.callback
             self.callback = None
             sublime.set_timeout(callback, 50)
     except GitHubApi.UnauthorizedException:
         sublime.error_message(self.ERR_UNAUTHORIZED)
         sublime.set_timeout(self.get_username, 50)
     except GitHubApi.UnknownException, e:
         sublime.error_message(e.message)
class OpenGistCommand(BaseGitHubCommand):
    """
    Open a gist.
    Defaults to all gists and copying it to the clipboard
    """
    MSG_SUCCESS = "Contents of '%s' copied to the clipboard."
    starred = False
    open_in_editor = False
    syntax_file_map = None
    copy_gist_id = False

    def run(self, edit):
        super(OpenGistCommand, self).run(edit)
        if self.github_token:
            self.get_gists()
        else:
            self.callback = self.get_gists
            self.get_token()

    def get_gists(self):
        self.gistapi = GitHubApi(self.github_token, debug=self.debug)
        try:
            self.gists = self.gistapi.list_gists(starred=self.starred)
            format = self.settings.get("gist_list_format")
            packed_gists = []
            for idx, gist in enumerate(self.gists):
                attribs = {
                    "index": idx + 1,
                    "filename": gist["files"].keys()[0],
                    "description": gist["description"] or ''
                }
                if isinstance(format, basestring):
                    item = format % attribs
                else:
                    item = [(format_str % attribs) for format_str in format]
                packed_gists.append(item)

            args = [packed_gists, self.on_done]
            if self.settings.get("gist_list_monospace"):
                args.append(sublime.MONOSPACE_FONT)
            self.view.window().show_quick_panel(*args)
        except GitHubApi.UnauthorizedException:
            sublime.error_message(self.ERR_UNAUTHORIZED_TOKEN)
            sublime.set_timeout(self.get_username, 50)
        except GitHubApi.UnknownException, e:
            sublime.error_message(e.message)
class OpenGistCommand(BaseGitHubCommand):
    """
    Open a gist.
    Defaults to all gists and copying it to the clipboard
    """
    MSG_SUCCESS = "Contents of '%s' copied to the clipboard."
    starred = False
    open_in_editor = False
    syntax_file_map = None
    copy_gist_id = False

    def run(self, edit):
        super(OpenGistCommand, self).run(edit)
        if self.github_token:
            self.get_gists()
        else:
            self.callback = self.get_gists
            self.get_token()

    def get_gists(self):
        self.gistapi = GitHubApi(self.github_token, debug=self.debug)
        try:
            self.gists = self.gistapi.list_gists(starred=self.starred)
            format = self.settings.get("gist_list_format")
            packed_gists = []
            for idx, gist in enumerate(self.gists):
                attribs = {"index": idx + 1,
                           "filename": gist["files"].keys()[0],
                           "description": gist["description"] or ''}
                if isinstance(format, basestring):
                    item = format % attribs
                else:
                    item = [(format_str % attribs) for format_str in format]
                packed_gists.append(item)

            args = [packed_gists, self.on_done]
            if self.settings.get("gist_list_monospace"):
                args.append(sublime.MONOSPACE_FONT)
            self.view.window().show_quick_panel(*args)
        except GitHubApi.UnauthorizedException:
            sublime.error_message(self.ERR_UNAUTHORIZED_TOKEN)
            sublime.set_timeout(self.get_username, 50)
        except GitHubApi.UnknownException, e:
            sublime.error_message(e.message)
Beispiel #14
0
from urllib.parse import urlparse
from enum import Enum
from github import GitHubApi
from students import get_students


def read_config(filename):
    with open(filename, "r") as file:
        config = json.load(file)
    return config


local_config = read_config("local_config.json")
config = read_config(local_config["config"])
oauth = config["oauth"]
github = GitHubApi(oauth["client_id"], oauth["client_secret"])
students = get_students(local_config["students"])


class ResultCode(Enum):
    SUCCESS = 0
    NO_PATH = 1
    NO_CODE = 2
    NO_PROG = 3


def check_repo(repo):
    url = urlparse(repo)
    parts = url.path.split('/')
    user = parts[1]
    repo_name = parts[2].replace('.git', '')
Beispiel #15
0
import csv
import requests
import json
from urllib.parse import urlparse
from github import GitHubApi
from students import get_students

def read_config(filename):
	with open(filename, "r") as file:
		config = json.load(file)
	return config
	
local_config = read_config("local_config.json")
config = read_config(local_config["config"])
oauth = config["oauth"]
github = GitHubApi(oauth["client_id"], oauth["client_secret"])

def check_hello_world(repo):
	res = requests.get(repo)
	if res.status_code == 404:
		return 1;
	url = urlparse(repo)
	parts = url.path.split('/')
	user = parts[1];
	repo = parts[2].replace('.git', '');
	print("{user} {repo}".format(user=user, repo=repo))
	check_folders = check_contents(user, repo, "/courses/prog_base/tasks/hello_world") 
	if not check_folders:
		return 2;
	if not check_contents(user, repo, "/courses/prog_base/tasks/hello_world/hello.c"):
		return 3;
Beispiel #16
0
import json
from urllib.parse import urlparse
from github import GitHubApi
from students import get_students


def read_config(filename):
    with open(filename, "r") as file:
        config = json.load(file)
    return config


local_config = read_config("local_config.json")
config = read_config(local_config["config"])
oauth = config["oauth"]
github = GitHubApi(oauth["client_id"], oauth["client_secret"])


def check_hello_world(repo):
    res = requests.get(repo)
    if res.status_code == 404:
        return 1
    url = urlparse(repo)
    parts = url.path.split('/')
    user = parts[1]
    repo = parts[2].replace('.git', '')
    print("{user} {repo}".format(user=user, repo=repo))
    check_folders = check_contents(user, repo,
                                   "/courses/prog_base/tasks/hello_world")
    if not check_folders:
        return 2