Skip to content
This repository has been archived by the owner on Jul 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #571 from joeferraro/revert-427-private-repos
Browse files Browse the repository at this point in the history
Revert "Ability to retrieve templates from Bitbucket and Github, includi...
  • Loading branch information
ralphcallaway committed May 4, 2015
2 parents 07bbfa7 + 850afab commit c281f97
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 52 deletions.
23 changes: 7 additions & 16 deletions mavensmate.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -174,26 +174,17 @@ To override default MavensMate settings, modify user-specific settings (MavensMa
".apxt"
],

//template location, e.g. "github" or "bitbucket" or "local". "remote" is synonymous with "github"
//template location, e.g. "remote" or "local" ("remote" refers to templates located on github)
"mm_template_location": "remote",

//template location
//if "mm_template_location" is set to "local", set to absolute location of the directory where you've forked the MavensMate-Templates project
"mm_template_source" : "/path/to/templates",

//if "mm_template_location" is set to "remote","github" or "bitbucket" set the repository owner, name and branch
"mm_template_repo_owner" : "joeferraro",
"mm_template_repo_name" : "MavensMate-Templates",
"mm_template_repo_branch" : "master",

//if you need to access a secured repository, set mm_template_auth to true, and set username and password as appropriate
//if using github, it is recommended that you generate an OAuth token here https://github.com/settings/applications#personal-access-tokens
//and set that as your username, leaving the password blank
//bitbucket does not appear to offer this capability at present
"mm_template_auth" : false,
"mm_template_username" : "",
"mm_template_password" : "",

//example: "mm_template_source" : "/path/to/templates"
//if "mm_template_location" is set to "remote", set to github location)
//example: "mm_template_source" : "username/reponame/branchname"
//project directory/repository must be in the format found here: https://github.com/joeferraro/MavensMate-Templates
"mm_template_source": "joeferraro/MavensMate-Templates/master",

//the default metadata available in a project (may be set on a per-project basis in the "advanced" tab of the new and edit project UIs)
"mm_default_subscription" : [
"ApexClass",
Expand Down
43 changes: 7 additions & 36 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from xml.dom.minidom import parse

import urllib.request
import base64

import MavensMate.config as config
import MavensMate.lib.apex.apex_extensions as apex_extensions
Expand Down Expand Up @@ -76,12 +75,16 @@ def parse_json_from_file(location):
def parse_templates_package(mtype=None):
try:
settings = sublime.load_settings('mavensmate.sublime-settings')
template_source = settings.get('mm_template_source', 'joeferraro/MavensMate-Templates/master')
template_location = settings.get('mm_template_location', 'remote')
if template_location == 'remote' or template_location == 'github' or template_location == 'bitbucket':
response = get_remote_package_json()
if template_location == 'remote':
if 'linux' in sys.platform:
response = os.popen('wget https://raw.githubusercontent.com/{0}/{1} -q -O -'.format(template_source, "package.json")).read()
else:
response = urllib.request.urlopen('https://raw.githubusercontent.com/{0}/{1}'.format(template_source, "package.json")).read().decode('utf-8')
j = json.loads(response)
else:
local_template_path = os.path.join(settings.get('mm_template_source'),"package.json")
local_template_path = os.path.join(template_source,"package.json")
debug(local_template_path)
j = parse_json_from_file(local_template_path)
if j == None or j == {}:
Expand All @@ -96,38 +99,6 @@ def parse_templates_package(mtype=None):
else:
return j

def get_remote_package_json():
settings = sublime.load_settings('mavensmate.sublime-settings')
auth = settings.get('mm_template_auth',False)
template_location = settings.get('mm_template_location', 'github')
template_repo_owner = settings.get('mm_template_repo_owner', 'joeferraro')
template__repo_name = settings.get('mm_template_repo_name', 'MavensMate-Templates')
template_repo_branch = settings.get('mm_template_repo_branch', 'master')
username = settings.get('mm_template_username')
password = settings.get('mm_template_password')

if template_location == 'github' or template_location == 'remote':
if auth:
endpoint = ("https://api.github.com/repos/{0}/{1}/contents/package.json?ref={2}").format(template_repo_owner, template__repo_name, template_repo_branch)
else:
endpoint = ("https://raw.githubusercontent.com/{0}/{1}/{2}/package.json").format(template_repo_owner, template__repo_name, template_repo_branch)
elif template_location == 'bitbucket':
endpoint = ("https://bitbucket.org/{0}/{1}/raw/{2}/package.json").format(template_repo_owner, template__repo_name, template_repo_branch)

if 'linux' in sys.platform:
if auth:
command = "wget {0} --header='Accept: application/vnd.github.VERSION.raw' --http-user={1} --http-password={2} -q -O -".format(endpoint, username, password)
else:
command = "wget {0} --header='Accept: application/vnd.github.VERSION.raw' -q -O -".format(endpoint)

return os.popen(command).read()

else:
req = urllib.request.Request(endpoint)
if auth:
req.add_header('Authorization', b'Basic ' + base64.b64encode(username.encode('ascii') + b':' + password.encode('ascii')))
req.add_header('Accept', 'application/vnd.github.VERSION.raw')
return urllib.request.urlopen(req).read().decode('utf-8')

def get_number_of_lines_in_file(file_path):
f = open(file_path)
Expand Down

0 comments on commit c281f97

Please sign in to comment.