Skip to content

Commit

Permalink
release 0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
xjsender committed Mar 15, 2015
1 parent 0632897 commit 04399ad
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 117 deletions.
10 changes: 9 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
0.0.4 (2015-03-14)
0.0.6 (2015-03-15)
++++++++++++++++++
* Add thread progress for CRUD on gist
* Refactoring this plugin, add callback support to thread
* If CRUD succeed, just hide the panel after lots of seconds
* Add a ``delay_seconds_for_hiding_panel`` setting to control the panel hiding delay seconds


0.0.5 (2015-03-14)
++++++++++++++++++
* Add two commands for default setting and user setting for HaoGist
* Update README.MD
Expand Down
13 changes: 13 additions & 0 deletions config/messages/0.0.6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Build 0.0.6
-----------
Release Date: 15 Mar 2015

* Add thread progress for CRUD on gist
* Refactoring this plugin, add callback support to thread
* If CRUD succeed, just hide the panel after lots of seconds
* Add a ``delay_seconds_for_hiding_panel`` setting to control the panel hiding delay seconds

Notes:

* You should restart your sublime after ``HaoGist`` is upgraded
-----------
3 changes: 3 additions & 0 deletions config/settings/HaoGist.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
// Some policy prevents setting chrome as default browser, so this setting is here
"default_chrome_path": "",

// Delay seconds for hiding panel
"delay_seconds_for_hiding_panel": 1,

// Files not shown in the sidebar and Command Palette
"file_exclude_patterns": [],

Expand Down
4 changes: 2 additions & 2 deletions config/settings/HaoGistPackage.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "HaoGist",
"version": "0.0.5",
"version": "0.0.6",
"description": "HaoGist is sublime plugin for CRUD on Github gist",
"author": "Hao Liu",
"email": "mouse.mliu@gmail.com",
"homepage": "https://github.com/xjsender/HaoGist",
"last_modified_date": "2015-03-14"
"last_modified_date": "2015-03-15"
}
File renamed without changes.
32 changes: 12 additions & 20 deletions api.py → gist/api.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import os
import json
import requests
from datetime import datetime

from .lib import util

GIST_BASE_URL = "https://api.github.com/%s"

class Gist(object):
class GistApi(object):
"""Gist API wrapper"""

def __init__(self, token):
self.res = None
self._token = token
self.headers = {
"Accept": "application/json",
Expand All @@ -32,35 +32,27 @@ def list(self, force=False):
return _gists

def get(self, url):
return requests.get(url, headers=self.headers)
self.res = requests.get(url, headers=self.headers)
return self.res

def retrieve(self, raw_url):
return requests.get(raw_url, headers=self.headers)
self.res = requests.get(raw_url, headers=self.headers)

def post(self, post_url, params):
"""POST to the web form"""

return requests.post(post_url, data=json.dumps(params),
print (params)
self.res = requests.post(post_url, data=json.dumps(params),
headers=self.headers)
return self.res

def patch(self, patch_url, params):
"""POST to the web form"""

return requests.patch(patch_url, data=json.dumps(params),
self.res = requests.patch(patch_url, data=json.dumps(params),
headers=self.headers)
return self.res

def delete(self, url):
return requests.delete(url, headers=self.headers)

def get_gist_by_id(self, gist_id):
_gists = self.list()
for _gist in self.list():
if gist_id == _gist["id"]:
return _gist

def get_gist_by_filename(self, fn):
_gists = self.list()
for _gist in _gists:
for key, value in _gist["files"].items():
if key == fn:
return _gist["files"][key], _gist
self.res = requests.delete(url, headers=self.headers)
return self.res
Empty file added gist/lib/__init__.py
Empty file.
69 changes: 69 additions & 0 deletions gist/lib/callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import os
import sublime

from . import util
from .panel import Printer

def refresh_gist(res, options):
# Get file_full_name
file_full_name = options["file_full_name"]
base, filename = os.path.split(file_full_name)

settings = util.get_settings()
with open(file_full_name, "wb") as fp:
fp.write(res.content)

Printer.get("log").write("%s update succeed" % filename)
sublime.set_timeout_async(Printer.get("log").hide_panel,
settings["delay_seconds_for_hiding_panel"] * 1000)

def delete_gist(res, options):
# Get file_full_name
file_full_name = options["file_full_name"]
base, filename = os.path.split(file_full_name)

settings = util.get_settings()

view = util.get_view_by_file_name(file_full_name)
if view:
sublime.active_window().focus_view(view)
sublime.active_window().run_command("close")
os.remove(file_full_name)
Printer.get("log").write("%s delete succeed" % filename)
sublime.set_timeout_async(Printer.get("log").hide_panel,
settings["delay_seconds_for_hiding_panel"] * 1000)

def create_gist(res, options):
# Get filename and content
filename = options["filename"]
content = options["content"]

# Get settings
settings = util.get_settings()

# Write file to workspace
file_full_name = settings["workspace"] + "/" + filename
with open(file_full_name, "wb") as fp:
fp.write(content.encode("utf-8"))

# Write cache to .cache/gists.json
util.add_gists_to_cache([res.json()])

# Open created gist
sublime.active_window().open_file(file_full_name)

# Success message
Printer.get("log").write("%s is created successfully" % filename)
sublime.set_timeout_async(Printer.get("log").hide_panel,
settings["delay_seconds_for_hiding_panel"] * 1000)

def update_gist(res, options):
# Get file_full_name
file_full_name = options["file_full_name"]
base, filename = os.path.split(file_full_name)

settings = util.get_settings()

Printer.get("log").write("%s is update successfully" % filename)
sublime.set_timeout_async(Printer.get("log").hide_panel,
settings["delay_seconds_for_hiding_panel"] * 1000)
File renamed without changes.
53 changes: 53 additions & 0 deletions gist/lib/progress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import sublime


class ThreadProgress():

"""
Animates an indicator, [= ], in the status area while a thread runs
:param thread:
The thread to track for activity
:param message:
The message to display next to the activity indicator
:param _callback:
The message to display once the thread is complete
"""

def __init__(self, api, thread, message, _callback, _callback_options={}):
self.api = api
self.thread = thread
self.message = message
self._callback = _callback
self._callback_options = _callback_options
self.addend = 1
self.size = 12
sublime.set_timeout(lambda: self.run(0), 100)

def run(self, i):
if not self.thread.is_alive():
if hasattr(self.thread, 'result') and not self.thread.result:
sublime.status_message('')
return

res = self.api.res
if not res or res.status_code > 399:
print (res.text)
return

# Invoke _callback
self._callback(res, self._callback_options)

return

before = i % self.size
after = (self.size - 1) - before

sublime.status_message('%s [%s=%s]' % (self.message, ' ' * before, ' ' * after))

if not after:
self.addend = -1
if not before:
self.addend = 1
i += self.addend

sublime.set_timeout(lambda: self.run(i), 100)
1 change: 1 addition & 0 deletions lib/util.py → gist/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def get_settings():
settings["file_exclude_patterns"] = s.get("file_exclude_patterns", {})
settings["folder_exclude_patterns"] = s.get("folder_exclude_patterns", [])
settings["default_chrome_path"] = s.get("default_chrome_path", "")
settings["delay_seconds_for_hiding_panel"] = s.get("delay_seconds_for_hiding_panel", 1)

return settings

Expand Down
Loading

0 comments on commit 04399ad

Please sign in to comment.