This file is indexed.

/usr/bin/pybit-client is in pybit-client 1.0.0-3.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/python

#       Copyright 2012:
#
#       Nick Davidson <nicholas.davidson@gmail.com>,
#       Simon Haswell <maxcady78@hotmail.co.uk>,
#       Neil Williams <codehelp@debian.org>,
#       James Bennet <github@james-bennet.com>
#
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

# -*- coding: utf-8 -*-
from amqplib import client_0_8 as amqp
import optparse
import tty
import sys
import signal
import jsonpickle
import requests
import pybit
import os
import daemon
import daemon.pidlockfile
import time
import logging
import lockfile
from logging.handlers import WatchedFileHandler
from pybitclient import PyBITClient
from pybitclient.debianclient import DebianBuildClient
from pybitclient.subversion import SubversionClient
from pybit.models import AMQPConnection

META = "PYBIT_CLIENT_"

PIDFILE = "/var/run/pybit-client.pid"

def signal_handler(signal, frame):
	try:
		print '\nClosing %s' % os.path.basename(__file__)
		sys.exit (os.EX_OK)
	except Exception as e:
		raise Exception('Error in signal handler: ' + str(e))
		return

def run(settings) :
	conn_info = AMQPConnection(pybit.get_client_queue(settings['clientid']),
				settings['host'], settings['userid'], settings['password'], settings['vhost'])
	with PyBITClient(settings['host_arch'], settings['distribution'], settings['pkg_format'], settings['suites'], conn_info, settings) as build_client:
		while True:
			if build_client is not None:
				build_client.wait()
			else:
				sys.exit (os.EX_OSERR)

def getDaemonLogger (filePath, format = None) :
	logger = logging.getLogger()
	logger.setLevel(logging.DEBUG)
	try:
		watchedHandler = WatchedFileHandler(filePath)
	except Exception as e:
		return e

	watchedHandler.setFormatter(logging.Formatter(format or '%(asctime)s %(msg)s'))
	logger.addHandler(watchedHandler)
	return (logger, watchedHandler)

if __name__ == '__main__':
	parser = optparse.OptionParser()
	#options we can override in the config file.
	groupConfigFile = optparse.OptionGroup(parser,
		"Config File Defaults","All the options which have defaults read from a config file.")
	groupConfigFile.add_option("--host_arch", dest="host_arch",
		help="Architecture to use, defaults to i386", metavar= META + "ARCH")

	groupConfigFile.add_option("--distribution",
		help="Distribution to use, defaults to Debian",
		metavar= META +"DIST")

	groupConfigFile.add_option("--pkg_format", dest="pkg_format",
		help="Package type to use, defaults to deb", metavar= META +"FORMAT")

	groupConfigFile.add_option("--suite", dest="suites", action="append",
		help="Suite to use, defaults to unstable. Can be passed multiple times.", metavar= META +"SUITES")

	groupConfigFile.add_option("--host", dest="host",
		help="host to connect to, defaults to localhost.",
		metavar=META + "HOST")

	groupConfigFile.add_option("--vhost", dest="vhost",
		help="vhost to connect to, defaults to localhost.",
		metavar=META + "VHOST")

	groupConfigFile.add_option("--userid", dest="userid",
		help="user id to use for AMQP server, defaults to guest.",
		metavar=META + "USERID")

	groupConfigFile.add_option("--port", dest="port",
		help="port to use for AMQP server, defaults to 5672",
		metavar=META + "PORT")

	groupConfigFile.add_option("--password", dest="password",
		help="password to use for AMQP server, defaults to guest",
		metavar=META + "PASSWORD")

	groupConfigFile.add_option("--clientid", dest="clientid",
		help="id to use for build-client control queue, defaults to 1 but is unique per amqp server.",
		metavar=META + "CLIENTID")

	groupConfigFile.add_option("--poll_time", dest="poll_time",
		help="interval at which to poll the queue, defaults to 60 s.",
		metavar=META + "POLL_TIME")

	groupConfigFile.add_option("--log_file", dest="log_file", 
		help="File to log client information.",
		metavar=META + "LOG_FILE")

	groupConfigFile.add_option("--pid_file", dest="pid_file", 
		help="File to pid client information.",
		metavar=META + "PID_FILE")



	parser.add_option_group(groupConfigFile)

	parser.add_option("--conf_file", dest="conf_file", default="client/client.conf",
		help="Config file to read settings from, defaults to client.conf which will be read from configs/client.conf and /etc/pybit/client.conf in turn.",
		metavar=META + "CONF_FILE")

	parser.add_option("-v", dest="verbose", action="store_true", default=False,
		help="Turn on verbose messages.", metavar=META+"VERBOSE")

	parser.add_option("-d", dest="daemonise", action="store_true", default=False,
		help="Daemonise with output going to /var/log/pybitclient.log by defalt",
		metavar=META+"DAEMONISE")

	(options, args) = parser.parse_args()
	(settings, opened_path) = pybit.load_settings(options.conf_file)
	settings = pybit.merge_options(settings, groupConfigFile, options)

#	Add default settings we want to not overwrite files.

	if  ( not 'log_file' in settings ):
		settings['log_file'] = "/var/log/pybitclient.log"

	if ( not 'pid_file' in settings ):
		settings['pid_file' ] = PIDFILE

	if options.daemonise :
		client_logger, watched_file_handler = getDaemonLogger( settings['log_file'] )
		if ( isinstance( client_logger, Exception ) ):
			print( "Fatal error creating client_logger: " + str( client_logger ) ) 
			sys.exit(os.EX_OSERR)
		lockfile = daemon.pidlockfile.PIDLockFile(settings['pid_file'])
		if (lockfile.is_locked()):
			logging.debug("PIDFile %s already locked" % settings['pid_file'])
			sys.exit(os.EX_OSERR)
		context = daemon.DaemonContext(
			working_directory=os.getcwd(),
			pidfile=lockfile,
			files_preserve = [ watched_file_handler.stream ],
			stderr=watched_file_handler.stream,
			stdout=watched_file_handler.stream)	
	 
		context.signal_map = {
			signal.SIGTERM: signal_handler,
			signal.SIGHUP:  signal_handler
			}
		logging.debug ("Daemonised")
	else :
#		FORMAT = format or '%(asctime)s %(msg)s'
		logging.basicConfig(level=logging.DEBUG)
		logging.debug ("Not daemonised")


	if settings == {}:
		logging.debug ("No settings found - exiting")
		sys.exit(os.EX_OSERR)
	if 'configured'  in settings and settings['configured'] == False:
		logging.debug ("Please configure your client.")
		sys.exit(os.EX_OK)

	if options.daemonise:
#		try:	
		with context :
			logging.debug ("I: Running build client.")
			run(settings)
#		except Exception as e:
#			logging.debug( "Failed to daemonise: " + str(e) )
#			sys.exit(os.EX_OSERR)
	
	else :
		print "Hit Ctrl-C to quit."
		run(settings)