Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Seanld/Latte
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.2
Choose a base ref
...
head repository: Seanld/Latte
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 7 commits
  • 3 files changed
  • 1 contributor

Commits on Jul 31, 2017

  1. Fixed README StaSh link

    Seanld committed Jul 31, 2017

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    dfbeccd View commit details
  2. Added new command: remove-repo

    Seanld committed Jul 31, 2017
    Copy the full SHA
    8d9ca88 View commit details
  3. Copy the full SHA
    328ac0a View commit details

Commits on Aug 1, 2017

  1. Copy the full SHA
    3079e22 View commit details

Commits on Feb 5, 2018

  1. Add files via upload

    Seanld authored Feb 5, 2018
    Copy the full SHA
    85df414 View commit details
  2. Delete carbon.png

    Seanld authored Feb 5, 2018
    Copy the full SHA
    0a0bf09 View commit details

Commits on Mar 9, 2024

  1. Copy the full SHA
    299ac21 View commit details
Showing with 43 additions and 30 deletions.
  1. +4 −14 README.md
  2. +1 −1 installer.py
  3. +38 −15 latte.py
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
<img src="latte.png" width="150px" height="150px" alt="Latte's logo" />

# Latte

`apt-get` for Pythonista.

*NOTE:* _There is a ton of introductory documentation located over at http://seanld.me/latte!_
`apt` for Pythonista.

## What's The Point?

When I was using (StaSh)[https://github.com/ywangd/stash] on Pythonista, I found it really annoying that I had to constantly run self-extracting Python scripts to install various add-ons and commands for StaSh. Because of that, I decided to create a simple utility that allows the creation, hosting, and sharing of software without hassle.

Now users of StaSh can easily communicate their software to other users. No more transfer problems.
When I was using [StaSh](https://github.com/ywangd/stash) on Pythonista, I found it really annoying that I had to constantly run self-extracting Python scripts to install various add-ons and commands for StaSh. Because of that, I decided to create a simple utility that allows the distribution of StaSh-based tools with less hassle.

Latte is also a platform for easily creating your own commands for StaSh. It allows you to install packages that install programs to StaSh's `stash_extensions/bin` directory. Now you can create your own commands!
Latte is also a platform for easily creating your own commands for StaSh.

## Installing

NOTICE: Latte is built to run on the StaSh shell. Make sure you have that installed before you run the installer code.

To install Latte to your Pythonista application, copy the below code, go to your Pythonista line-interpreter (the panel that swipes over on the right, that lets you type in Python code line-by-line), and paste the code, and run it. This should run the installer program provided in the repository. Once it starts running, you should start seeing your new package manager being installed to your StaSh.
To install Latte to Pythonista, copy the below code, go to your Pythonista line-interpreter (the panel that swipes over on the right, that lets you type in Python code line-by-line), and paste the code, and run it. This should run the installer program provided in the repository. Once it starts running, you should start seeing your new package manager being installed to your StaSh.

```python
import requests as r; exec(r.get("https://raw.githubusercontent.com/Seanld/Latte/master/installer.py").text);
```

## Getting Started

If you want to learn how to properly use Latte, you can head over to http://seanld.me/latte. There's plenty of information over there to get you started!
2 changes: 1 addition & 1 deletion installer.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

print("Downloading...")

request = requests.get("https://raw.githubusercontent.com/Seanld/Latte/dev/latte.py")
request = requests.get("https://raw.githubusercontent.com/Seanld/Latte/master/latte.py")
data = request.text

print("Installing...")
53 changes: 38 additions & 15 deletions latte.py
Original file line number Diff line number Diff line change
@@ -3,16 +3,16 @@
import requests
import sys
import argparse
from os import remove, mkdir, rename, listdir
from os import remove, mkdir, rename, listdir, getcwd
from shutil import rmtree

cwd = os.getcwd()
cwd = getcwd()
documentsIndex = cwd.index("Documents")
documentsIndex += len("Documents")
ROOT = cwd[:documentsIndex]

class stansi: # Collection of Stash's ANSI escape codes.
bold = u"\x9b1m"
bold = u"\033[1m"
underscore = u"\x9b4m"
attr_end = u"\x9b0m"

@@ -42,6 +42,10 @@ def Green(text):
return stansi.fore_green+text+stansi.fore_end
def Cyan(text):
return stansi.fore_cyan+text+stansi.fore_end
def Success(text):
return stansi.fore_green+stansi.bold+text+stansi.attr_end
def Error(text):
return stansi.fore_red+stansi.bold+text+stansi.attr_end

class SWConfig (object): # Parser for the config files such as the repository listing.
def __init__(self, content):
@@ -57,6 +61,14 @@ def __getitem__(self, key):
def keys(self):
return self.data.keys()

def remove_line(content, lines_list):
pointer = 0
for line in lines_list:
if content in line:
lines_list.pop(pointer)
pointer += 1
return lines_list

def download_package(url, package_name): # Handles the installation of packages directories (since they're no longer tarfiles)
content_listing = ["bin.py", "meta.latte"]
mkdir(ROOT+"/"+package_name)
@@ -65,7 +77,7 @@ def download_package(url, package_name): # Handles the installation of packages
content = requested.text
requested.close()
if content == "404: Not Found\n":
print(Red("ERROR") + ": Package not found.")
print(Error("ERROR") + ": Package not found.")
sys.exit()
opened = open(ROOT+"/"+package_name+"/"+item, "w")
opened.write(content)
@@ -82,7 +94,7 @@ def main(sargs):
opened.close()
except:
opened = open(".latte-repos.swconf", "w")
print(Red("WARNING") + ": Repository listing doesn't exist, rebuilding to default...")
print(Error("WARNING") + ": Repository cache doesn't exist, rebuilding to default...")
opened.write("universe=https://raw.githubusercontent.com/Seanld/latte-universe/master")
opened.close()

@@ -100,11 +112,11 @@ def main(sargs):

repo_to_use = REPOSITORIES["universe"]
package_name = packageSplitted[0]
print(Red("WARNING") + ": No repository specified, using universe by default...")
print(Error("WARNING") + ": No repository specified, using universe by default...")
try:
download_package(repo_to_use, package_name)
except:
stoutput("ERROR", "Couldn't find package", "error")
print(Error("ERROR") + ": Failed to find package")
sys.exit()
# Move to correct locations
print("Installing")
@@ -115,15 +127,15 @@ def main(sargs):
rename(ROOT+"/"+package_name+"/meta.latte", ROOT+"/stash_extensions/latte/"+package_name+".latte")
rename(ROOT+"/"+package_name+"/bin.py", ROOT+"/stash_extensions/bin/"+package_name+".py")
rmtree(ROOT+"/"+package_name)
print(Green("SUCCESS") + ": Package '"+package_name+"' successfully installed!")
print(Success("SUCCESS") + ": Package '"+package_name+"' successfully installed!")
elif args.method == "remove":
try:
remove(ROOT+"/stash_extensions/bin/"+args.package+".py")
remove(ROOT+"/stash_extensions/latte/"+args.package+".latte")
except:
print(Red("ERROR") + ": Couldn't remove package; not found in resources.")
print(Error("ERROR") + ": Couldn't remove package; not found in resources.")
sys.exit()
print(Green("SUCCESS") + ": '"+args.package+"' removed!")
print(Success("SUCCESS") + ": '"+args.package+"' removed!")
elif args.method == "update":
print("Jeez! Sorry, but we are currently working on self-update capabilities. For now, just redo the install process to update.")
elif args.method == "new":
@@ -135,9 +147,9 @@ def main(sargs):
index = open(args.package+"/bin.py", "w")
index.write("# This is just an example template. You can change this all you like.\n\nimport sys\nimport argparse\n\ndef main(sargs):\n\tparser = argparse.ArgumentParser()\n\tparser.add_argument('echo', help='What you want the command to echo back.')\n\targs = parser.parse_args(sargs)\n\t\n\tprint('Echoing back: '+args.echo)\n\nif __name__ == '__main__':\n\tmain(sys.argv[1:])")
index.close()
print(Green("SUCCESS") + ": Package '"+args.package+"' generated, check current working directory!")
print(Success("SUCCESS") + ": Package '"+args.package+"' generated, check current working directory!")
except:
print(Red("ERROR") + ": Couldn't generate package; directory may already exist.")
print(Error("ERROR") + ": Couldn't generate package; directory may already exist.")
elif args.method == "add-repo":
try:
request = requests.get(args.package+"/init.latte")
@@ -148,9 +160,9 @@ def main(sargs):
repo_listing = open(".latte-repos.swconf", "a")
repo_listing.write("\n"+nickname+"="+args.package)
repo_listing.close()
print(Green("SUCCESS") + ": '"+nickname+"' added to repositories!")
print(Success("SUCCESS") + ": '"+nickname+"' added to repositories cache!")
except:
print(Red("ERROR") + ": Either repository doesn't exist, or does not contain an 'init.latte' file.")
print(Error("ERROR") + ": Either repository doesn't exist, or does not contain an 'init.latte' file.")
elif args.method == "list-repos":
if args.package == "all":
opened = open(".latte-repos.swconf")
@@ -159,8 +171,19 @@ def main(sargs):
as_config = SWConfig(content)
for repo in as_config.keys():
print(Cyan(repo) + ": " + Green(as_config[repo]))
elif args.method == "remove-repo":
opened = open(".latte-repos.swconf", "r")
data = opened.read().splitlines()
opened.close()

removed = remove_line(args.package, data)
opened = open(".latte-repos.swconf", "w")
opened.writelines(removed)
opened.close()

print(Success("SUCCESS") + ": Removed '" + args.package + "' from repository cache!")
else:
print(Red("ERROR") + ": Unknown command '"+args.method+"'!")
print(Error("ERROR") + ": Unknown command '"+args.method+"'!")

if __name__ == "__main__":
main(sys.argv[1:])