Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ueffel committed Feb 27, 2018
0 parents commit 630b038
Show file tree
Hide file tree
Showing 7 changed files with 627 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Keypirinha Package Control
==========================

This is a package for the fast keystroke launcher keypirinha
(http://keypirinha.com/). It provides commands to install, update and remove
third party packages.

## Usage

All commands are prefixed with `PackageControl:`.

## Installation

### Directly from Keypirinha

* Open the `Keypirinha: Console`
* Enter the following:
```python
import keypirinha as kp,keypirinha_net as kpn,os;p="PackageControl.keypirinha-package";d=kpn.build_urllib_opener().open("https://github.com/ueffel/Keypirinha-PackageControl/releases/download/0.1/"+p);pb=d.read();d.close();pp=os.path.join(kp.installed_package_dir(), p);f=open(pp, "wb");f.write(pb);f.close()
```

### Manually

* Download the `PackageControl.keypirinha-package` from the [releases](https://github.com/ueffel/Keypirinha-PackageControl/releases/latest)
* Copy the file in your %APPDATA%\Keypirinha\InstalledPackages directory (or <Keypirinha_Home>\portable\Profile\InstalledPackages)
54 changes: 54 additions & 0 deletions build_package.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
@echo off
set PACKAGE_NAME=PackageControl

set SEVENZIP=
where 7z > nul 2>&1
if not errorlevel 1 (
set SEVENZIP=7z
goto done_sevenzip
)

where 7za > nul 2>&1
if not errorlevel 1 (
set SEVENZIP=7za
goto done_sevenzip
)

if exist "c:\Program Files (x86)\7-Zip\7z.exe" (
set "SEVENZIP=c:\Program Files (x86)\7-Zip\7z.exe"
goto done_sevenzip
)

if exist "c:\Program Files (x86)\7-Zip\7za.exe" (
set "SEVENZIP=c:\Program Files (x86)\7-Zip\7za.exe"
goto done_sevenzip
)

if exist "c:\Program Files\7-Zip\7z.exe" (
set "SEVENZIP=c:\Program Files\7-Zip\7z.exe"
goto done_sevenzip
)

if exist "c:\Program Files\7-Zip\7za.exe" (
set "SEVENZIP=c:\Program Files\7-Zip\7za.exe"
goto done_sevenzip
)

if not defined SEVENZIP (
echo 7zip not found
exit /b 1
)
:done_sevenzip

:pack
if exist %PACKAGE_NAME%.keypirinha-package (
del %PACKAGE_NAME%.keypirinha-package
)
echo Using "%SEVENZIP%" to pack
"%SEVENZIP%" a -mx9 ^
-tzip "%PACKAGE_NAME%.keypirinha-package" ^
-x!%~nx0 ^
-xr!.git ^
-x@.gitignore ^
-x!.gitignore ^
*
53 changes: 53 additions & 0 deletions lib/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import json
import os


class Package:
"""
Represents a keypirinha package
"""
def __init__(self, name, version, desc, date, dl_url, filename):
self.name = name
self.version = version
self.description = desc
self.date = date
self.download_url = dl_url
self.filename = filename if filename else "{}.keypirinha-package".format(name)

def download(self, opener, directory):
"""
Downloads the file from download_url and saves it to the given directory
"""
with opener.open(self.download_url) as dl, \
open(os.path.join(directory, self.filename), "wb") as package:
for chunk in iter(lambda: dl.read(4096), ""):
if not chunk:
break
package.write(chunk)
os.utime(os.path.join(directory, self.filename), times=(self.date.timestamp(), self.date.timestamp()))

def to_dict(self):
"""
Creates a dictionary from the package object
"""
obj = {
"download_url": self.download_url,
"name": self.name,
"filename": self.filename,
"date": self.date.strftime("%Y-%m-%dT%H:%M:%S%z"),
"description": self.description,
"version": self.version
}
return obj

def to_json(self):
"""
Create json string from the package object
"""
return json.dumps(self.to_dict(), sort_keys=True, indent=4)

def __repr__(self):
"""
Readable representation of the package object (json)
"""
return self.to_json()
Binary file added packagecontrol.ico
Binary file not shown.
8 changes: 8 additions & 0 deletions packagecontrol.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[main]
# Decides which packages are available to install
repository = http://ueffel.bplaced.de/uni/packages.json

# List of the installed packages
# this list is automatically updated, no need to add anything here in the file directly
# installed packages are checked on startup, if anything isn't present, it will be installed
#installed_packages =
Loading

0 comments on commit 630b038

Please sign in to comment.