PK!qtibl_cli/__init__.pyfrom .ui import *PK!Wi??tibl_cli/__version__.pyVERSION = (0, 0, 1) __version__ = '.'.join(map(str, VERSION)) PK!Ztibl_cli/exc.pyclass TiblError(Exception): pass class TiblFormatError(TiblError): def __init__(self, message): self.message = message pass class TiblFileError(TiblError): def __init__(self, message): self.message = message pass PK!99tibl_cli/tibl.pyimport logging import shutil import getpass import os from http.server import HTTPServer, SimpleHTTPRequestHandler from git import Repo from git.exc import * from .exc import * git_logger = logging.getLogger("git") git_logger.setLevel(logging.INFO) log = logging.getLogger(__name__) logging.basicConfig(level=logging.DEBUG) # Disable logging because too verbose for now. log.disabled = True git_logger.disabled = True class Tibl: """ Represents a tibl instance. TODO: Separate git and non git code. This way, it will be easier to use tibl-cli without git. Git code is changes, pull, and push. """ def __init__(self, name): """ Create a tibl instance object to talk with tibl. Tries to get git repo if it is present. Otherwise, you won't be able to use pull/push feature. :param name: name of the tibl site """ self.name = name def new(self, post_type, post_name, title): """ Create a new post and add it to the database :param post_type: Item type. Can be post or page. :param post_name: File name of the post :param title: Title that you'll have on the post listing """ # Check input validity # Check if post_type exists if post_type not in ["post", "page"]: log.error("Invalid post type supplied.") raise TiblFormatError("Invalid post type supplied") # Check if there's non ascii characters into the post name if len(post_name) != len(post_name.encode()): log.error("Invalid characters in post name. Please use only ascii.") raise TiblFormatError( "Invalid characters in post name. Please use only ascii." ) # Check if there's any spaces in the post name if " " in post_name: log.error("Don't use spaces in post name.") raise TiblFormatError("Don't use spaces in post name.") # End of check # Add markdown extention filename = post_name + ".md" # add a _ to separate pages and posts if post_type == "page": filename = "_" + filename # Add path to topics filename = "data/topics/" + filename # Check if file exists if os.path.isfile(filename): log.error("File {} already exists.".format(filename)) raise TiblFileError("File {} already exists.".format(filename)) # Creating file try: with open(filename, "w") as f: f.write("# {}".format(title)) log.info("Created item at {}".format(filename)) except FileNotFoundError as e: # echo_err("Could not create post at {}.".format(os.getcwd()) log.error( "Could not create post at {}".format(os.getcwd() + "/" + filename) ) log.error("Ensure that you are at your site root :)") raise TiblFileError( "Could not create post. Ensure thatyou are at your site root" ) # Updating database # TODO: Add at the beginning of the list rather than # at the end ? if post_type == "post": try: with open("data/database.md", "a") as f: f.write( "* [{}](t.html?{}={})\n".format( title, "t" if post_type == "post" else "p", post_name ) ) except FileNotFoundError as e: raise TiblFileError( "Could not find database at {}".format( os.getcwd() + "/data/database.md" ) ) else: log.info("Not updating database since you've created a page") def serve(self, port=8080): """ Start a tiny http server that enables the user to visit its site. :param port: Port to use. Default is 8080 """ server_address = ("localhost", port) httpd = HTTPServer(server_address, SimpleHTTPRequestHandler) log.info("Serving at http://{}:{}".format(*server_address)) httpd.serve_forever() def create(name): """ Create a new instance of tibl on the self.name folder """ if name not in [None, ""]: if os.path.exists(name): log.error("directory already exists") raise FileExistsError try: Repo.clone_from("https://github.com/Uinelj/tibl", name) shutil.rmtree("{}/.git".format(name), ignore_errors=True) except GitCommandError as e: print(e) print("Error {} cloning tibl".format(e.status)) raise TiblGitError(e, "Error {} cloning tibl".format(e.status)) PK! tibl_cli/ui.pyimport logging import sys import click import blindspin import crayons from .tibl import Tibl from .exc import * def cli_print(string, level="ok", prefix="🗿", bold=False): ret = prefix + " " + string if level == "ok": click.echo(crayons.green(ret, bold=bold)) elif level == "wrn": click.echo(crayons.yellow(ret, bold=bold)) elif level == "err": click.echo(crayons.red(ret, bold=bold)) elif level == "dbg": click.echo(crayons.magenta(ret, bold=bold)) else: click.echo(ret) @click.group() def cli(): pass @cli.command(help="Create a new tibl site") @click.option("--name", prompt="Site directory") def create(name): """ Clone the master branch of tibl into the specified folder. :param name: Name of the folder. Should work with directories. """ ret = "" click.echo("Creating tibl site...") with blindspin.spinner(): try: Tibl.create(name) except FileExistsError as e: cli_print("directory {} already exists".format(name), level="err") sys.exit(1) cli_print("tibl site {} created !".format(name), level="ok") sys.exit(0) @cli.command(help="Create a new post/page") @click.option( "--post_type", prompt="Item type:", default="post", help="can be post or page." ) @click.option( "--post_name", prompt="File name: ", default="hello", help="don't use spaces or non-ascii characters", ) @click.option( "--title", prompt="Item title: ", default="Hi", help="this will be the title of your new item", ) def new(post_type, post_name, title): """ Create a new post and add it to the database :param post_type: Item type. Can be post or page. :param post_name: File name of the post :param title: Title that you'll have on the post listing """ tibl = Tibl(".") try: tibl.new(post_type, post_name, title) except TiblFileError: cli_print( "Unable to create {}, ensure that you are in your site's directory".format( post_name ), level="err", ) sys.exit(1) except TiblFormatError as e: cli_print(e.message, level="err") sys.exit(1) cli_print("Created {}: {}".format(post_type, post_name)) @cli.command(help="serve your website locally") @click.option("--port", default=8080, help="server port") def serve(port): """ Start a tiny http server that enables the user to visit its site. """ tibl = Tibl(".") cli_print("Serving on localhost:{}...".format(port)) tibl.serve(port) if __name__ == "__main__": cli() PK!H't&()tibl_cli-0.0.2.dist-info/entry_points.txtN+I/N.,()*Lʱ9Vz@ PK! -## tibl_cli-0.0.2.dist-info/LICENSEMIT License Copyright (c) 2018 uj Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HlŃTTtibl_cli-0.0.2.dist-info/WHEEL A н#J@Z|Jmqvh&#hڭw!Ѭ"J˫( } %PK!HB!rDF!tibl_cli-0.0.2.dist-info/METADATASN0SRTm' ApS$IvG+vCLܐرcJx)t)JղR{]6J&^Hi C{'ZnF49H9[L^9Z&ʤFwlƭ0*% RNk_BfGxUz}uϣ'aR '% W4|}kU&̙܉R:yM)>f\|qڔ> p|}坨w;'s@\˨w‰h ?ݨGx+ow~{SS⁡h56M2[k C.!^T=š\9ig©䌄RGvmt2_`:'7п2_pNi[7 YZya PI :\ߐ92(@wT1z=R mxx, tߏl2Ci2QM{pFO  :PXeِZ ,UV[_iPK!H tibl_cli-0.0.2.dist-info/RECORD}ι@Ѽl(6 :`kPAl g&pt'ѹ?FW !*pQOD1oZ9TȩUѫݐ\eZUB~RiQUMg,u@E1owZ{O7N%n&XWP:V~E&klѵm*y)!XokÆ=.R9JY*Lkݧ8d$8=f=Xܛ>by7q;ydF`ܓdeb"f {ty*yår;|lJ,SdE4WwU PK!qtibl_cli/__init__.pyPK!Wi??Ctibl_cli/__version__.pyPK!Ztibl_cli/exc.pyPK!99tibl_cli/tibl.pyPK! Jtibl_cli/ui.pyPK!H't&()" tibl_cli-0.0.2.dist-info/entry_points.txtPK! -## tibl_cli-0.0.2.dist-info/LICENSEPK!HlŃTT$tibl_cli-0.0.2.dist-info/WHEELPK!HB!rDF!%tibl_cli-0.0.2.dist-info/METADATAPK!H (tibl_cli-0.0.2.dist-info/RECORDPK *