Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
brewchecker is now pip-installable!
Browse files Browse the repository at this point in the history
brewchecker is now executable from command line (if `pip install`'ed)!

All operations on files/dirs (git/hg/svn checkout) now performed in tmp dir!
  • Loading branch information
mktums committed May 5, 2015
1 parent 12fa5b6 commit a9528e2
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 39 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include brewchecker/inject.rb
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,18 @@
> _Linus Torvalds_
## What it is?
**brew404** is a tool for checking [Homebrew](http://brew.sh/) packages' availability, written in Python.
**brewchecker** is a tool for checking [Homebrew](http://brew.sh/) packages' availability, written in Python.

## What it does?
It downloads latest [Homebrew sources](https://github.com/homebrew/homebrew), scans [`Formula`](https://github.com/Homebrew/homebrew/tree/master/Library/Formula) folder for formulas, parse every of them, and tries to download every package, patch, etc from 'stable' section.
It downloads latest [Homebrew sources](https://github.com/homebrew/homebrew) to temporary folder, scans [`Formula`](https://github.com/Homebrew/homebrew/tree/master/Library/Formula) folder for formulas, parse every of them, and tries to download every package, patch, etc from 'stable' section.

**Output of this script is JSON document with statuses of all Formulas' resources.**

## Installation
### Requirements
#### Python packages
**brew404** mostly rely on `stdlib`'s modules and `pip`'s VCS interface. Also, it uses [`pycurl`](http://pycurl.sourceforge.net/).

To install latest versions of them:

``` bash
pip install --upgrade pip pycurl
```

#### System-wide applications
You must have `libcurl` library installed, and follow VCS binaries in `PATH`:

* `git`
* `hg`
* `bzr` (currently not used by Homebrew, but we have to support it)
Expand All @@ -37,13 +29,20 @@ On OS X you can get all this by using **Homebrew**
brew install git hg bzr cvs svn fossil curl
```

### Getting sources
### Installation
To install **brewchecker** use following command:

``` bash
pip install brewchecker
```

#### Getting sources
``` bash
git clone https://github.com/mktums/brew404
git clone https://github.com/mktums/brewchecker
```

## Usage
So far it's just
``` bash
./main.py
brewchecker
```
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'mktums'
1 change: 1 addition & 0 deletions brewchecker/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# coding: utf-8
8 changes: 4 additions & 4 deletions downloaders.py → brewchecker/downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import os
import shutil
from urlparse import urlparse

import pycurl
import time

from pip.exceptions import InstallationError
from pip.vcs.bazaar import Bazaar
import time

from settings import USER_AGENT, REPOS_DIR
from vcs import CustomGit, CustomHg, CustomSVN, CVS, Fossil
from brewchecker.settings import USER_AGENT, REPOS_DIR
from brewchecker.vcs import CustomGit, CustomHg, CustomSVN, CVS, Fossil


class Downloader(object):
Expand Down
7 changes: 3 additions & 4 deletions formula.py → brewchecker/formula.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# coding: utf-8
import sys
from downloaders import (
from brewchecker.downloaders import (
CurlDownloader, GitDownloader, ApacheDownloader, SubversionDownloader, MercurialDownloader,
CVSDownloader, BazaarDownloader, FossilDownloader
)
from report import FormulaReport, LibraryReport
from utils import color_status, color, SlicableDict
from brewchecker.report import FormulaReport, LibraryReport
from brewchecker.utils import SlicableDict


class Resource(object):
Expand Down
File renamed without changes.
16 changes: 11 additions & 5 deletions main.py → brewchecker/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#!/usr/bin/env python
# coding: utf-8
import json
import os
import subprocess
import signal
from multiprocessing.pool import ThreadPool

from formula import Library
from settings import BREW_BIN, THREADS
from utils import bold, update_sources, signal_handler
import click

from brewchecker.formula import Library
from brewchecker.settings import BREW_BIN, THREADS, BASE_DIR
from brewchecker.utils import update_sources, signal_handler

signal.signal(signal.SIGINT, signal_handler)

Expand All @@ -31,7 +33,8 @@ def get_json(self, brew_bin=BREW_BIN):
Since Homebrew's `irb` command can change it's behavior in future, it's best for us to manually find
start of JSON output.
"""
irb_proc = subprocess.Popen([brew_bin, 'irb', '-r', './inject.rb'], stdout=subprocess.PIPE)
inject_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'inject.rb')
irb_proc = subprocess.Popen([brew_bin, 'irb', '-r', inject_file], stdout=subprocess.PIPE)
self.json = subprocess.check_output(['sed', '1,2d'], stdin=irb_proc.stdout)
return self

Expand All @@ -42,7 +45,9 @@ def load(self):
return library


@click.command()
def main():
update_sources()
loader = Loader().get_json()
lib = loader.load()
pool = ThreadPool(THREADS)
Expand All @@ -53,5 +58,6 @@ def main():

if __name__ == '__main__':
# print u"\U0001F37A " + bold("Homebrew link checker")
update_sources()
main()

os.removedirs(BASE_DIR)
2 changes: 1 addition & 1 deletion report.py → brewchecker/report.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding: utf-8
from utils import SlicableDict
from brewchecker.utils import SlicableDict


class FormulaReport(object):
Expand Down
12 changes: 12 additions & 0 deletions brewchecker/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# coding: utf-8
import os
import tempfile

BASE_DIR = tempfile.mkdtemp()
BREW_GIT_URL = "git+https://github.com/Homebrew/homebrew.git"
BREW_CLONE_DIR = os.path.join(BASE_DIR, 'homebrew')
BREW_BIN = BREW_CLONE_DIR + '/bin/brew'
BREW_FORMULAS_DIR = BREW_CLONE_DIR + '/Library/Formula'
REPOS_DIR = os.path.join(BASE_DIR, 'repos')
USER_AGENT = "Homebrew 0.9.5 (Ruby 2.0.0-481; Mac OS X 10.9.5)"
THREADS = 10
3 changes: 2 additions & 1 deletion utils.py → brewchecker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pip._vendor.distlib.compat import OrderedDict
from pip.vcs.git import Git

from settings import BREW_CLONE_DIR, BREW_GIT_URL
from brewchecker.settings import BREW_CLONE_DIR, BREW_GIT_URL, BASE_DIR


def color(this_color, string_):
Expand Down Expand Up @@ -108,4 +108,5 @@ def __delitem__(self, key, *args, **kwargs):

def signal_handler(signal, frame):
print '\rYou pressed Ctrl+C!'
os.removedirs(BASE_DIR)
sys.exit(0)
2 changes: 1 addition & 1 deletion vcs.py → brewchecker/vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pip.vcs.mercurial import Mercurial
from pip.vcs.subversion import Subversion, get_rev_options

from utils import CD
from brewchecker.utils import CD


class CustomGit(Git):
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pycurl==7.19.5.1
pycurl==7.19.5.1
click==4.0
pip>=6.1.1
8 changes: 0 additions & 8 deletions settings.py

This file was deleted.

24 changes: 24 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from setuptools import setup, find_packages

setup(
name='brewchecker',
version='0.1',
packages=find_packages(),
install_requires=[
'Click',
'pycurl',
'pip>=6.1.1',
],
include_package_data=True,
url='https://github.com/mktums/brewchecker',
license='MIT',
author='Mike Tums',
author_email='mktums@gmail.com',
description="brewchecker is a tool for checking Homebrew packages'availability, written in Python.",
entry_points={
'console_scripts': [
'brewchecker = brewchecker.main:main',
]
},
long_description=open('README.rst').read()
)

0 comments on commit a9528e2

Please sign in to comment.