Skip to content

Commit

Permalink
Merge pull request #152 from james02135/Intool-v4
Browse files Browse the repository at this point in the history
Refactored tutorial page, dashboard.html, created new how.html. Appli…
  • Loading branch information
james02135 authored Apr 27, 2021
2 parents 00770a7 + b8bd11e commit e306b86
Show file tree
Hide file tree
Showing 16 changed files with 566 additions and 270 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ install:
# Send build notifications to the following email addresses
notifications:
email:
- [email protected]
- [email protected]
recipients:
- [email protected]
- [email protected]
on_success: always
on_failure: always
script:
- echo "no scripts"
238 changes: 238 additions & 0 deletions auth/bin/html5-print
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
#!/home/james/Tooling-Project/auth/bin/python3
# -*- coding: utf-8 -*-
#
# Copyright 2014 Bernard Yue
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from __future__ import unicode_literals, absolute_import

__prog__ = 'html5-print'

# standard libraries
import os
import sys
import argparse
import codecs
import textwrap
import warnings
if sys.version_info[0] >= 3:
from urllib.parse import urlparse
else:
from urlparse import urlparse

# third parties libraries
import requests

# my libraries
import html5print


class Main(object):
"""Application Class"""

def beautifyHTML(self, text, indent=2, encoding=None,
formatter="minimal"):
"""Pretty print html with indentation of `indent` per level
:param text: html as string
:param indent: width of indentation
:param encoding: encoding of `text`
:param formatter: formatter to use by bs4
:return : beautified `text`
"""
return html5print.HTMLBeautifier.beautify(text, indent=indent,
encoding=encoding,
formatter=formatter)

def beautifyJS(self, text, indent=2, encoding=None):
"""beautifying javascript `text` by reindending to width of `indent`
per level `text` is expected to be a valid javascript (i.e. no html
comment(s) tag <!-- ... -->).
:param text: valid javascript as string
:param indent: width of indentation
:param encoding: expected encoding of `text`. If None, it will be
guesssed
:return : reindented javascript
"""
return html5print.JSBeautifier.beautify(text, indent=indent,
encoding=encoding)

def beautifyCSS(self, text, indent=2, encoding=None):
"""beautifying css `text` by reindending to width of `indent` per
level. `text` is expected to be a valid CSS (i.e. no html
comment(s) tag <!-- ... -->).
:param text: valid CSS as multiline string
:param indent: width od indentation per level
:param encoding: expected encoding of `text`. If None, it will be
guesssed
:return : reindented CSS
"""
return html5print.CSSBeautifier.beautify(text, indent=indent,
encoding=encoding)

def run(self):
"""main entry point of this script
:return : None
"""
self.args = self.parseArgs()
args = self.args
self.process(args.filetype, args.infile, args.outfile,
args.indent_width, args.encoding)

def parseArgs(self):
"""parsing input arguments
:return : a parser.parse_arg() object
"""
formatter_class = argparse.RawDescriptionHelpFormatter
desc = textwrap.dedent("""\
Beautify HTML5, CSS, Javascript - Version {} (By {})
This tool reformat the input and return a beautified version,
in unicode.
""".format(html5print.__version__, html5print.__author__))
parser = argparse.ArgumentParser(prog=__prog__,
formatter_class=formatter_class,
description=desc)
parser.add_argument('infile', type=str,
help='filename | url | -, a dash, which'
' represents stdin')
parser.add_argument('-o', '--output', dest='outfile',
default='',
help='filename for formatted html, stdout'
' if omitted')
parser.add_argument('-s', '--indent-width', dest='indent_width',
type=int, action='store', default=2,
help='number of space for indentation, default 2')
parser.add_argument('-e', '--encoding', dest='encoding', type=str,
action='store', default=None,
help='encoding of input, default UTF-8')
parser.add_argument('-t', '--filetype', dest='filetype', type=str,
choices=['html', 'js', 'css'],
action='store', default='HTML',
help='type of file to parse, default html')
parser.add_argument('-v', '--version', action='version',
version='%(prog)s Version ' +
html5print.__version__)
return parser.parse_args()

def process(self, filetype, infile, outfile, indent, encoding):
"""main process workflow
:param filetype: type of file to parse (html, js or css)
:param infile: name of input file, '-' for stdin
:param outfile: name of output file, stdout if empty
:param indent: width of an indent level
:param encoding: encoding of infile
:return : None
"""
filetype = filetype.upper()
text = self.read(infile)
text = html5print.decodeText(text, encoding)
if filetype == 'HTML':
output = self.beautifyHTML(text, indent, encoding, "html5")
elif filetype == 'CSS':
output = self.beautifyCSS(text, indent) + os.linesep
else:
# javascript
output = self.beautifyJS(text, indent) + os.linesep
self.write(outfile, output)

def read(self, filename):
"""read content from filename, and stdin if filename = ''
:return : html as string
"""
if filename == '-':
filename = ''
sys.stderr.write('Press Ctrl-D when finished' + os.linesep)
sys.stderr.flush()

parsed = urlparse(filename)
if parsed.scheme in ('', 'file'):
if sys.version_info[0] >= 3:
data = self.py3GetData(filename)
else:
data = self.py2GetData(filename)
else:
r = requests.get(filename)
data = r.content
return data

def py2GetData(self, filename):
"""read all contains in `filename` and return a byte stream. Python
2.x version.
:param filename: name of file to read data from. `-` represents stdin
:return : a byte stream (i.e. b'...')
"""
data = ''
if filename:
with open(filename, 'rU') as fh:
data = fh.read()
else:
sys.stdin.flush()
data = sys.stdin.read()
return data

def py3GetData(self, filename):
"""read all contains in `filename` and return a byte stream. Python
3.x version.
:param filename: name of file to read data from. `-` represents stdin
:return : a byte stream (i.e. b'...')
"""
data = ''
if filename:
with open(filename, 'rb') as fh:
data = fh.read()
else:
sys.stdin.flush()
data = sys.stdin.buffer.read()
return data

def write(self, filename, data):
"""write `data` to `filename`, if 'filename` is '', write to stdout
:return : None
"""
if sys.version_info[0] >= 3:
self.py3WriteData(data, filename)
else:
self.py2WriteData(data, filename)

def py2WriteData(self, data, filename):
"""write unicode to file, python 2.x version"""
if filename:
with codecs.open(filename, 'wU', encoding='utf-8') as fh:
fh.write(data)
else:
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
sys.stdout.write(data)
sys.stdout.flush()

def py3WriteData(self, data, filename):
"""write unicode to file, python 3.x version"""
if filename:
with open(filename, 'w', encoding='utf-8') as fh:
fh.write(data)
else:
sys.stdout.write(data)
sys.stdout.flush()


if __name__ == '__main__':
try:
Main().run()
except IOError as e:
if e.strerror.lower() == 'broken pipe':
exit(0)
raise
except LookupError as e:
print(e.message)
exit(2)
else:
exit(0)
33 changes: 33 additions & 0 deletions auth/bin/slimit
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/home/james/Tooling-Project/auth/bin/python3
# EASY-INSTALL-ENTRY-SCRIPT: 'slimit==0.8.1','console_scripts','slimit'
import re
import sys

# for compatibility with easy_install; see #2198
__requires__ = 'slimit==0.8.1'

try:
from importlib.metadata import distribution
except ImportError:
try:
from importlib_metadata import distribution
except ImportError:
from pkg_resources import load_entry_point


def importlib_load_entry_point(spec, group, name):
dist_name, _, _ = spec.partition('==')
matches = (
entry_point
for entry_point in distribution(dist_name).entry_points
if entry_point.group == group and entry_point.name == name
)
return next(matches).load()


globals().setdefault('load_entry_point', importlib_load_entry_point)


if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(load_entry_point('slimit==0.8.1', 'console_scripts', 'slimit')())
1 change: 1 addition & 0 deletions tooling_project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def load_user(user_id):
return user
return None


# blueprint for form routes in the app
from .auth import auth as auth_blueprint

Expand Down
14 changes: 10 additions & 4 deletions tooling_project/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def login_post():
# If both checks pass, this is an authenticated user
login_user(user)
print(request.data)
flash('Logged in successfully')
flash("Logged in successfully")
return redirect(url_for(dashboard))
else:
print(form.errors)
Expand Down Expand Up @@ -137,13 +137,19 @@ def menu_post():
token = user.github_token
# Send the POST request to the GitHub api
url = "https://api.github.com/user/repos"
payload = {"name": project_name, "description": "for school", "auto_init": "true"}
payload = {
"name": project_name,
"description": "for school",
"auto_init": "true",
}
headers = {
"Authorization": f"token {token}",
"Content-Type": "text/plain",
"Cookie": "_octo=GH1.1.1061749589.1617981576; logged_in=no",
}
response = requests.request("POST", url, headers=headers, data=json.dumps(payload))
response = requests.request(
"POST", url, headers=headers, data=json.dumps(payload)
)
print(request.data)
print(response.text)
return redirect(url_for(dashboard))
Expand All @@ -157,4 +163,4 @@ def menu_post():
@login_required
def logout():
logout_user()
return redirect(url_for("main.home"))
return redirect(url_for("main.home"))
12 changes: 7 additions & 5 deletions tooling_project/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from flask import (
Blueprint,
render_template
)
from flask import Blueprint, render_template
from flask_login import login_required, current_user


Expand Down Expand Up @@ -36,8 +33,13 @@ def tutorial():
return render_template("tutorial.html")


@main.route("/how")
def how():
return render_template("how.html")


@main.route("/dashboard")
@login_required
def dashboard():
# Name and ID are used as variable in the html page
return render_template("dashboard.html", name=current_user.name, ID=current_user.id)
return render_template("dashboard.html", name=current_user.name, ID=current_user.id)
Binary file added tooling_project/static/img/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tooling_project/templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h1>About Intool</h1>
</div>
<p class="lead">Automated project initialization, notification, and connection tool</p>
<p>
Intool was created to tackle the issue of "How to successfully create a project framework for any module". By using this tool in conjuntion
Intool was created to tackle the issue of "How to successfully create a project framework for any module". By using this tool in conjunction
with specifications from your lecturers, you will be more able to navigate the complex waters of college assignments.
</p>
<p>
Expand Down
Loading

0 comments on commit e306b86

Please sign in to comment.