Skip to content

Commit

Permalink
geoinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
jabbalaci committed Nov 3, 2013
1 parent 776a692 commit 7a2f38c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion jabbapylib/apps/pandora.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import os
import sys
from jabbapylib.console.autoflush import unbuffered
from jabbapylib.geo import geoinfo
from jabbapylib.podium import podium
from lxml import etree
from jabbapylib.network.ping import ping
from jabbapylib.network import geoinfo

XML = 'foxyproxy.xml'
BAK = 'foxyproxy.bak'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

"""
Some useful decorators.
"jd" stands for "jabba's decorator" :)
dec_time:
jd_time:
print debug info when entering a function
print debug info when quitting a function
print elapsed time while executing the function
print execution time of the function
dec_requires:
jd_requires:
Useful if you call external programs/commands.
If the given command doesn't exist, you will get
an error immediately.
# from jabbapylib.decorators.decorators import dec_time
# from jabbapylib.decorators.decorators import dec_requires
# from jabbapylib.decorators.decorators import jd_time
# from jabbapylib.decorators.decorators import jd_requires
"""

import time
Expand All @@ -23,7 +24,10 @@
import os


def dec_time(func):
def jd_time(func):
"""
For debugging the execution time of a function.
"""
def wrapper(*arg):
start = time.time()
print '# dec_time: enter', func.func_name
Expand All @@ -35,7 +39,14 @@ def wrapper(*arg):
return wrapper


def dec_requires(fpath):
def jd_requires(fpath):
"""
Verify if the given external command is available.
Useful when writing "shell scripts" and you want to make
an external call. If the command (parameter fpath) to be
called is not available, you get an error message right away.
"""
def _decorator(fn):
if not fs.which(fpath):
print "Error: {f} doesn't exist".format(f=fpath)
Expand All @@ -48,13 +59,13 @@ def step_func(*args, **kwargs):
return _decorator


@dec_time
@jd_time
def wait():
time.sleep(3)


@dec_requires("date")
# @dec_requires("vim") ## you could register several requirements
@jd_requires("date")
# @jd_requires("vim") ## you could register several requirements
def something():
os.system("date")

Expand Down
1 change: 1 addition & 0 deletions jabbapylib/geo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'jabba'
File renamed without changes.
3 changes: 2 additions & 1 deletion tests/network/test_geoinfo.py → tests/geo/test_geoinfo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from jabbapylib.network import geoinfo
from jabbapylib.geo import geoinfo


def test_geo():
ip = '173.194.35.177' # Google
Expand Down

0 comments on commit 7a2f38c

Please sign in to comment.