Author: dmeyer
Date: Fri Aug 24 14:46:49 2007
New Revision: 2787
Log:
rename and split bin scripts again
Added:
trunk/beacon/bin/beacon-daemon
- copied, changed from r2785, /trunk/beacon/bin/beacond
trunk/beacon/bin/beacon-mount
- copied, changed from r2785, /trunk/beacon/bin/beacon
trunk/beacon/bin/beacon-search
- copied, changed from r2785, /trunk/beacon/bin/beacon
Removed:
trunk/beacon/bin/beacon
trunk/beacon/bin/beacond
Modified:
trunk/beacon/setup.py
trunk/beacon/src/__init__.py
Copied: trunk/beacon/bin/beacon-daemon (from r2785, /trunk/beacon/bin/beacond)
==============================================================================
--- /trunk/beacon/bin/beacond (original)
+++ trunk/beacon/bin/beacon-daemon Fri Aug 24 14:46:49 2007
@@ -65,9 +65,9 @@
def usage(error_code):
- print 'beacond [options]'
+ print 'beacon-daemon [options]'
print 'options:'
- print '--stop stop an existing beacond process'
+ print '--stop stop an existing beacon-daemon process'
print '--greedy makes beacon eat all available CPU for indexing'
print '--monitor colon-delimited paths to index and monitor
(augments'
print ' config file)'
@@ -135,14 +135,14 @@
def shutdown(client):
client.rpc('beacon.shutdown')
kaa.notifier.step()
- print 'Shutdown command issued to beacond.'
+ print 'Shutdown command issued to beacon-daemon.'
sys.exit(0)
try:
client = kaa.beacon.Client()
client.signals['connect'].connect(shutdown, client)
except kaa.beacon.ConnectError:
- print 'beacond does not appear to be runing.'
+ print 'beacon-daemon does not appear to be runing.'
sys.exit(1)
kaa.notifier.loop()
sys.exit(0)
@@ -155,7 +155,7 @@
try:
# this should not be possible
kaa.beacon.connect()
- print 'beacond is already running.'
+ print 'beacon-daemon is already running.'
sys.exit(1)
except kaa.beacon.ConnectError:
pass
Copied: trunk/beacon/bin/beacon-mount (from r2785, /trunk/beacon/bin/beacon)
==============================================================================
--- /trunk/beacon/bin/beacon (original)
+++ trunk/beacon/bin/beacon-mount Fri Aug 24 14:46:49 2007
@@ -44,7 +44,7 @@
# FIXME: most of this list should probably be kept in kaa.db
IGNORE_KEYS = [ 'name', 'parent', 'parent_id', 'parent_type', 'media', 'mtime',
- 'computed_id', 'type', 'id' ]
+ 'computed_id', 'type', 'id' ]
# insert kaa path information
__site__ = '../lib/python%s.%s/site-packages' % sys.version_info[:2]
@@ -55,203 +55,55 @@
# kaa imports
import kaa.notifier
import kaa.db
-import kaa.beacon
import kaa.utils
+import kaa.beacon
+from kaa.beacon.fusefs import BeaconFS, FuseError
# get logging object
log = logging.getLogger('beacon')
def usage(error_code):
- print 'beacon [options] [search terms]'
+ print 'beacon-mount [options] path [search terms]'
print 'options:'
- print '--info displays info about the database'
- print '--type type searches only the given file types (use --info
to show types)'
- print '--monitor do not exit after search and monitor for changes'
- print '--details show detailed metadata in search results'
- print '--mount dirname mount the query at a given mountpoint (requires
FUSE)'
- print '--umount dirname umounts a beacon FUSE mountpoint'
- print '--list-media lists all known media'
- print '--del-media media delete given media from the database'
- print '--debug Enables debugging mode for all loggers'
- print '--help | -h this message'
- print
+ print '-u --umount umounts a beacon FUSE mountpoint'
+ print '--type type searches only the given file types'
print
print 'Search terms can be arbitrary keywords or key=value pairs. e.g.'
- print ' beacon Helden Blind'
- print ' beacon dirname=/local/video'
- print ' beacon --monitor dirname=/local/video'
- print ' beacon artist=Silbermond'
- print ' beacon --type image vacation'
- print ' beacon --mount ~/buffy buffy'
+ print ' beacon ~/results artist=Someone'
+ print ' beacon -u ~/results'
sys.exit(error_code)
-def print_results(results, detailed = False):
- def fit(s, l):
- """
- Fits string s in length l by replacing middle characters with '...'
- """
- if len(s) > l:
- over = len(s) - l + 3
- return s[:(len(s)-over)/2] + '...' + s[(len(s)+over)/2:]
- return s
-
- if len(results) == 0:
- print 'No results.'
- return
-
- # Get terminal dimensions
- try:
- h, w = struct.unpack('hh', fcntl.ioctl(sys.stdin.fileno(),
termios.TIOCGWINSZ, 'xxxx'))
- except:
- w = 75
-
- valid_results = [len(x.get('type')) for x in results if x.get('type')]
- if len(valid_results):
- type_col_len = max(valid_results) + 1
- type_col_len = max(type_col_len, 4)
- else:
- type_col_len = 4
- uri_col_len = min(w - 1 - type_col_len - 2, max([len(x.url) for x in
results]))
- print 'Type'.ljust(type_col_len), 'URI'.ljust(uri_col_len)
- print '-' * type_col_len, '-' * uri_col_len
- for r in results:
- t = r.get('type')
- if t is None:
- t = '???'
- print t.ljust(type_col_len), fit(r.url, uri_col_len)
- if detailed:
- for key in r.keys():
- if r.get(key) and key not in IGNORE_KEYS:
- print ' ' * (type_col_len + 5) + '| %s: %s' % (key,
r.get(key))
-
-
-
-def progress(cur, total, item):
- n = 0
- if total > 0:
- n = int((cur / float(total)) * 50)
- sys.stdout.write("|%51s| %d / %d\r" % (("="*n + ">").ljust(51), cur,
total))
- sys.stdout.flush()
- if cur == total:
- print
-
-def changed(result):
- print '\nBeacon query update:'
- print_results(result, details)
-
-def uptodate():
- print 'Beacon has finished the query and parsing.'
-
-
if __name__ == '__main__':
try:
- # list of modes this script can start in
- possible_modes = [ 'info', 'mount', 'umount', 'list-media',
'del-media']
-
# read arguments
- opts = [ 'db=', 'fg', 'autoshutdown', 'logfile=', 'verbose=', 'help',
'type=',
- 'monitor', 'debug', 'details' ] + possible_modes
- opts, args = getopt.gnu_getopt(sys.argv[1:], 'h', opts)
+ opts = [ 'umount', 'help', 'type=' ]
+ opts, args = getopt.gnu_getopt(sys.argv[1:], 'hu', opts)
except getopt.GetoptError:
usage(1)
- logfile = ''
- mountpt = ''
- mode = 'search'
- detach = True
- shutdown = False
- monitor = False
qtype = None
- details = False
- database = os.path.expanduser("~/.beacon")
-
for o, a in opts:
- if o.startswith('--') and o[2:] in possible_modes:
- if mode != 'search':
- usage(1)
- mode = o[2:]
- elif o == '--db':
- database = a
- elif o == '--fg':
- detach = False
- elif o == '--autoshutdown':
- shutdown = True
- elif o == '--logfile':
- logfile = os.path.realpath(a)
- elif o == '--verbose':
- a = a.lower()
- if a == 'all':
- logging.getLogger('beacon').setLevel(logging.INFO)
- else:
- for m in a.split(','):
- logging.getLogger('beacon.' + m).setLevel(logging.INFO)
- elif o == '--debug':
- # Set DEBUG level on root logger
- logging.getLogger().setLevel(logging.DEBUG)
- elif o == '--monitor':
- monitor = True
+ if o == '-u':
+ # umount
+ mountpt = args.pop(0)
+ os.system('fusermount -u %s' % mountpt)
+ sys.exit(0)
elif o == '--type':
qtype = a
- elif o == '--details':
- details = True
elif o in ('--help', '-h'):
usage(0)
- if mode == 'search' and not args:
- usage(0)
+ mountpt = args.pop(0)
+ if not os.path.isdir(mountpt):
+ print "Mount point %s is not a directory" % mountpt
+ sys.exit(1)
- if mode == 'umount':
- mountpt = args.pop(0)
- os.system('fusermount -u %s' % mountpt)
- sys.exit(0)
-
- if mode in ('search', 'info', 'mount', 'list-media', 'del-media'):
- try:
- kaa.beacon.connect()
- except kaa.beacon.ConnectError:
- print 'beacond not running.'
- sys.exit(1)
-
-
- if mode == 'info':
- info = kaa.beacon.get_db_info()
- print 'Beacon database information:'
- print
- print 'Total objects:'.rjust(20), info['total']
- print 'Indexed keywords:'.rjust(20), info['wordcount']
- print
- print 'Object breakdown by type:'
- for key in info['count']:
- print (key + ':').rjust(15), info['count'][key]
- sys.exit(0)
-
-
- if mode == 'mount':
- mountpt = args.pop(0)
- if not os.path.isdir(mountpt):
- print "Mount point %s is not a directory" % mountpt
- sys.exit(1)
-
-
- if mode == 'list-media':
- for m in kaa.beacon.query(type='media', media='ignore').get():
- print '%4d %s' % (m['id'], m['name'])
- sys.exit(0)
-
-
- if mode == 'del-media':
- try:
- media = int(args.pop(0))
- except:
- print 'media must be an int'
- sys.exit(1)
- if media == 0:
- print 'media 0 can\'t be deleted'
- sys.exit(1)
- kaa.beacon.delete_media(media)
- sys.exit(0)
-
+ try:
+ kaa.beacon.connect()
+ except kaa.beacon.ConnectError:
+ print 'beacon-daemon not running.'
+ sys.exit(1)
query = {}
if qtype:
@@ -284,45 +136,20 @@
else:
result = kaa.beacon.query(**query)
- if mode == 'mount':
- from kaa.beacon.fusefs import BeaconFS, FuseError
- fs = BeaconFS(mountpt, result)
- try:
- fs.check()
- except FuseError, e:
- print e
- sys.exit(1)
-
- if detach:
- if not logfile:
- logfile = os.path.join(database, 'fuse.log')
- # FIXME: should only daemonize when we know fs is mounted.
- kaa.utils.daemonize(stdout = logfile)
-
- thread = kaa.notifier.Thread(fs.main)
- thread.signals["exception"].connect(lambda dummy:
kaa.notifier.shutdown())
- thread.start()
-
- kaa.notifier.loop()
- sys.exit(0)
-
-
- if not monitor:
- def print_results_and_exit(result):
- t2 = time.time()
- print_results(result, details)
- print 'Query took %s seconds; %d results' % ((t2-t1), len(result))
- sys.exit(0)
- if not result.valid:
- # Query is pending, connect to changed signal to display results.
- result.signals['changed'].connect_once(print_results_and_exit,
result)
- else:
- print_results_and_exit(result)
- else:
- result.signals['changed'].connect(changed, result)
- result.signals['progress'].connect(progress)
- result.signals['up-to-date'].connect(uptodate)
- result.monitor()
+ fs = BeaconFS(mountpt, result)
+ try:
+ fs.check()
+ except FuseError, e:
+ print e
+ sys.exit(1)
+
+ database = os.path.dirname(kaa.beacon.get_db_info()['file'])
+ logfile = os.path.join(database, 'fuse.log')
+ # FIXME: should only daemonize when we know fs is mounted.
+ kaa.utils.daemonize(stdout = logfile)
+
+ thread = kaa.notifier.Thread(fs.main)
+ thread.signals["exception"].connect(lambda dummy: kaa.notifier.shutdown())
+ thread.start()
kaa.notifier.loop()
- sys.exit(0)
Copied: trunk/beacon/bin/beacon-search (from r2785, /trunk/beacon/bin/beacon)
==============================================================================
--- /trunk/beacon/bin/beacon (original)
+++ trunk/beacon/bin/beacon-search Fri Aug 24 14:46:49 2007
@@ -62,14 +62,12 @@
log = logging.getLogger('beacon')
def usage(error_code):
- print 'beacon [options] [search terms]'
+ print 'beacon-search [options] [search terms]'
print 'options:'
print '--info displays info about the database'
print '--type type searches only the given file types (use --info
to show types)'
print '--monitor do not exit after search and monitor for changes'
print '--details show detailed metadata in search results'
- print '--mount dirname mount the query at a given mountpoint (requires
FUSE)'
- print '--umount dirname umounts a beacon FUSE mountpoint'
print '--list-media lists all known media'
print '--del-media media delete given media from the database'
print '--debug Enables debugging mode for all loggers'
@@ -82,7 +80,6 @@
print ' beacon --monitor dirname=/local/video'
print ' beacon artist=Silbermond'
print ' beacon --type image vacation'
- print ' beacon --mount ~/buffy buffy'
sys.exit(error_code)
@@ -147,38 +144,25 @@
if __name__ == '__main__':
try:
# list of modes this script can start in
- possible_modes = [ 'info', 'mount', 'umount', 'list-media',
'del-media']
+ possible_modes = [ 'info', 'list-media', 'del-media']
# read arguments
- opts = [ 'db=', 'fg', 'autoshutdown', 'logfile=', 'verbose=', 'help',
'type=',
+ opts = [ 'verbose=', 'help', 'type=',
'monitor', 'debug', 'details' ] + possible_modes
opts, args = getopt.gnu_getopt(sys.argv[1:], 'h', opts)
except getopt.GetoptError:
usage(1)
- logfile = ''
- mountpt = ''
mode = 'search'
- detach = True
- shutdown = False
monitor = False
qtype = None
details = False
- database = os.path.expanduser("~/.beacon")
for o, a in opts:
if o.startswith('--') and o[2:] in possible_modes:
if mode != 'search':
usage(1)
mode = o[2:]
- elif o == '--db':
- database = a
- elif o == '--fg':
- detach = False
- elif o == '--autoshutdown':
- shutdown = True
- elif o == '--logfile':
- logfile = os.path.realpath(a)
elif o == '--verbose':
a = a.lower()
if a == 'all':
@@ -201,16 +185,11 @@
if mode == 'search' and not args:
usage(0)
- if mode == 'umount':
- mountpt = args.pop(0)
- os.system('fusermount -u %s' % mountpt)
- sys.exit(0)
-
- if mode in ('search', 'info', 'mount', 'list-media', 'del-media'):
+ if mode in ('search', 'info', 'list-media', 'del-media'):
try:
kaa.beacon.connect()
except kaa.beacon.ConnectError:
- print 'beacond not running.'
+ print 'beacon-daemon not running.'
sys.exit(1)
@@ -227,13 +206,6 @@
sys.exit(0)
- if mode == 'mount':
- mountpt = args.pop(0)
- if not os.path.isdir(mountpt):
- print "Mount point %s is not a directory" % mountpt
- sys.exit(1)
-
-
if mode == 'list-media':
for m in kaa.beacon.query(type='media', media='ignore').get():
print '%4d %s' % (m['id'], m['name'])
@@ -284,29 +256,6 @@
else:
result = kaa.beacon.query(**query)
- if mode == 'mount':
- from kaa.beacon.fusefs import BeaconFS, FuseError
- fs = BeaconFS(mountpt, result)
- try:
- fs.check()
- except FuseError, e:
- print e
- sys.exit(1)
-
- if detach:
- if not logfile:
- logfile = os.path.join(database, 'fuse.log')
- # FIXME: should only daemonize when we know fs is mounted.
- kaa.utils.daemonize(stdout = logfile)
-
- thread = kaa.notifier.Thread(fs.main)
- thread.signals["exception"].connect(lambda dummy:
kaa.notifier.shutdown())
- thread.start()
-
- kaa.notifier.loop()
- sys.exit(0)
-
-
if not monitor:
def print_results_and_exit(result):
t2 = time.time()
Modified: trunk/beacon/setup.py
==============================================================================
--- trunk/beacon/setup.py (original)
+++ trunk/beacon/setup.py Fri Aug 24 14:46:49 2007
@@ -77,7 +77,8 @@
version = '0.1.0',
license = 'LGPL',
summary = "Media-oriented virtual filesystem",
- scripts = [ 'bin/kaa-thumb', 'bin/beacon', 'bin/beacond' ],
+ scripts = [ 'bin/kaa-thumb', 'bin/beacon-daemon',
'bin/beacon-search',
+ 'bin/beacon-mount' ],
rpminfo = {
'requires': 'python-kaa-base >= 0.1.2, imlib2 >= 1.2.1',
'build_requires': 'python-kaa-base >= 0.1.2, imlib2-devel >= 1.2.1,
python-devel >= 2.4.0'
Modified: trunk/beacon/src/__init__.py
==============================================================================
--- trunk/beacon/src/__init__.py (original)
+++ trunk/beacon/src/__init__.py Fri Aug 24 14:46:49 2007
@@ -62,10 +62,10 @@
debugging = """
------------------------------------------------------------------------
-The system was unable to connect to beacon. Please check if the beacon
-server is running properly. If beacon processes exist, please kill them.
-Start beacon in an extra shell for better debugging. Start beacon with
-beacon --start --verbose all --fg
+The system was unable to connect to beacon-daemon. Please check if the
+beacon daemon is running properly. If beacon-daemon processes exist,
+please kill them. Start beacon in an extra shell for better debugging.
+beacon-daemon --start --verbose all --fg
------------------------------------------------------------------------
"""
@@ -87,8 +87,8 @@
except RuntimeError:
# It was possible to connect to the beacon server but not
# to the thumbnailer. Something is very wrong.
- log.error('unable to connect to beacon %s', debugging)
- raise RuntimeError('Unable to connect to beacon')
+ log.error('unable to connect to beacon-daemon %s', debugging)
+ raise RuntimeError('Unable to connect to beacon-daemon')
signals = _client.signals
log.info('beacon connected')
return _client
@@ -98,18 +98,18 @@
"""
Lauch a beacon server.
"""
- beacon = os.path.dirname(__file__), '../../../../../bin/beacon'
+ beacon = os.path.dirname(__file__), '../../../../../bin/beacon-daemon'
beacon = os.path.realpath(os.path.join(*beacon))
if not os.path.isfile(beacon):
# we hope it is in the PATH somewhere
- beacon = 'beacon'
+ beacon = 'beacon-daemon'
cmd = '%s --start --verbose=%s' % (beacon, verbose)
if autoshutdown:
cmd += ' --autoshutdown'
if os.system(cmd):
- log.error('unable to connect to beacon %s', debugging)
- raise RuntimeError('Unable to connect to beacon')
+ log.error('unable to connect to beacon-daemon %s', debugging)
+ raise RuntimeError('Unable to connect to beacon-daemon')
return connect()
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog