def get_resource_content(request, source_name): """ Returns the actual resource. Tries to guess the mimetype. If it fails, returns application/octet-stream as fallback. """ import mimetypes mimetypes.init() resource_id = request.GET.get('resource_id', None) if not resource_id: raise Http404 try: source = Source.objects.get(name=source_name) except Source.DoesNotExist: response_data = {'error': 'Source not found'} else: response_data = Backend(source.backend_id).get_resource_content(source, resource_id) if 'content' in response_data.keys(): content = response_data['content'] mimetype, encoding = mimetypes.guess_type(response_data['name']) if not mimetype: mimetype = 'application/octet-stream' else: content = response_data mimetype = "application/json" return HttpResponse(content, mimetype=mimetype)
def run(self): # Print a list of available backends output = [('Backends ({0}):'.format(len(Backend.list_backends())), 'underline_bold_blue')] for backend in Backend.list_backends(): output.append(('- ' + backend, 'blue')) self.out(*output)
def check_config(): """ Check crucial configuration details for existence and workability. Runs checks to see whether bugtracker's URL is reachable, whether backend is available at the right filename, and whether the script has the key arguments it needs to run: URL, backend, and database details. The filename for the backend in the backends/ directory needs to be the same as the configuration argument specifying that backend. For instance, invoking the Launchpad backend uses 'lp', and so the filename is 'lp.py'. """ Config.check_params(['url', 'backend']) if Config.backend + ".py" not in Backend.get_all_backends(): raise InvalidConfig('Backend "' + Config.backend + '" does not exist') url = urlparse.urlparse(Config.url) check_url = urlparse.urljoin(url.scheme + '://' + url.netloc, '') print("Checking URL: " + check_url) req = Request(check_url) try: response = urlopen(req) except HTTPError, e: raise InvalidConfig('The server could not fulfill the request ' + str(e.msg) + '(' + str(e.code) + ')')
def check_config(): """ Check crucial configuration details for existence and workability. Runs checks to see whether bugtracker's URL is reachable, whether backend is available at the right filename, and whether the script has the key arguments it needs to run: URL, backend, and database details. The filename for the backend in the backends/ directory needs to be the same as the configuration argument specifying that backend. For instance, invoking the Launchpad backend uses 'lp', and so the filename is 'lp.py'. """ Config.check_params(['url', 'backend']) if Config.backend + ".py" not in Backend.get_all_backends(): raise InvalidConfig('Backend "' + Config.backend + '" does not exist') url = urlparse.urlparse(Config.url) check_url = urlparse.urljoin(url.scheme + '://' + url.netloc, '') print("Checking URL: " + check_url) req = Request(check_url) if Config.backend != 'github': try: response = urlopen(req) except HTTPError, e: raise InvalidConfig('The server could not fulfill the request ' + str(e.msg) + '(' + str(e.code) + ')') except URLError, e: raise InvalidConfig('We failed to reach a server. ' + str(e.reason))
def run(self, name, backend): # Validate the parameters form = AddAccountForm(name=name, backend=backend) if not form.validate(): self.err(**form.errors) return # Ask the user for the backend configuration options backend = Backend.get_backend(backend) config = {'backend': form.data['backend']} for field in backend.config_form(): self.out((field.label.text, 'blue')) value = input('> ').strip() if value: config[field.name] = value # Validate the users configuration result = backend.validate_config(**config) if not result[0]: self.err('Invalid backend config:', **result[1]) return # Create the new account account = Account(name=form.data['name'], backend=config) account.insert() self.out(('Account added: {0}'.format(account.api_key), 'bold_green'))
def run(self, name): # Validate the parameters form = ConfigAccountBackendForm(name=name) if not form.validate(): self.err(**form.errors) return # Find the account to be configured account = Account.one(Q.name == form.data['name']) # Let the user know to use dash to clear existing values self.out(('* Enter dash (-) to clear the existing value', 'underline_bold_blue')) # Ask the user for the backend configuration options backend = Backend.get_backend(account.backend['backend']) config = {'backend': account.backend['backend']} for field in backend.config_form(): # Request the value self.out((field.label.text, 'blue')) value = input('({0}) > '.format(account.backend.get( field.name, ''))) value = value.strip() # Check if the value should be set to the original, cleared or used # as provided. if value: if value == '-': continue else: config[field.name] = value else: if account.backend.get(field.name): config[field.name] = account.backend.get(field.name) # Validate the users configuration result = backend.validate_config(**config) if not result[0]: self.err('Invalid backend config:', **result[1]) return # Update the accounts backend account.backend = config account.update('modified', 'backend') self.out(('Account configured', 'bold_green'))
def check_config(): """ """ Config.check_params(['url', 'backend']) if Config.backend + ".py" not in Backend.get_all_backends(): raise InvalidConfig('Backend "' + Config.backend + '" does not exist') url = urlparse.urlparse(Config.url) check_url = urlparse.urljoin(url.scheme + '://' + url.netloc, '') print("Checking URL: " + check_url) req = Request(check_url) try: response = urlopen(req) except HTTPError, e: raise InvalidConfig('The server could not fulfill the request ' + str(e.msg) + '(' + str(e.code) + ')')
def check_config(): """ """ Config.check_params(['url','backend']) if Config.backend+".py" not in Backend.get_all_backends(): raise InvalidConfig('Backend "'+ Config.backend + '" does not exist') url = urlparse.urlparse(Config.url) check_url = urlparse.urljoin(url.scheme + '://' + url.netloc,'') print("Checking URL: " + check_url) req = Request(check_url) try: response = urlopen(req) except HTTPError, e: raise InvalidConfig('The server could not fulfill the request ' + str(e.msg) + '('+ str(e.code)+')')
def main(): """ """ # Note: Default values for options are defined in # configuration module usage = 'Usage: %prog [options]' try: Config.set_config_options(usage) except (ErrorLoadingConfig, InvalidConfig), e: printerr(str(e)) sys.exit(2) try: backend = Backend.create_backend(Config.backend) except ImportError, e: printerr("Backend ''" + Config.backend + "'' doesn't exist. " + str(e)) sys.exit(2) printdbg("Bicho object created, options and backend initialized") backend.run() if Config.logtable: try: ilogger = IssueLogger.create_logger(Config.backend) except ImportError, e: printerr("Logger ''" + Config.backend + "'' doesn't exist. " + str(e)) sys.exit(2) printdbg("Bicho logger object created") ilogger.run()
def __init__(self, name): Backend.__init__(self, name) self._pdftocairo = os.path.join(self._utilsdir, 'pdftocairo')
def __init__(self, name): Backend.__init__(self, name) self._pdftops = os.path.join(self._utilsdir, 'pdftops');
def get_backend_instance(self): """Return a configured instance of the backend for the account""" backendCls = Backend.get_backend(self.backend['backend']) return backendCls(**self.backend)
import chess import chess.pgn import os path = os.path.dirname(os.path.abspath(__file__)) #w = Weights("./384x30-t60-4300.pb.gz") w = Weights(path + "/128x10-t60-2-5300.pb.gz") w1100 = Weights(path + "/1000-1200-scratch-swa-36000.pb.gz") w1450 = Weights(path + "/1400-1500-scratch-swa-60000.pb.gz") w1750 = Weights(path + "/1700-1800-scratch-swa-60000.pb.gz") w2150 = Weights(path + "/2000-2100-scratch-swa-60000.pb.gz") start_fen = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1' back = Backend(weights=w) b1100 = Backend(weights=w1100) b1450 = Backend(weights=w1450) b1750 = Backend(weights=w1750) b2150 = Backend(weights=w2150) board = chess.Board() fen = board.fen() start_fen = fen pgn = open("game8.pgn") game = chess.pgn.read_game(pgn) names = ["1100", "1450", "1750", "2150", "128x10"] board = game.board()
def __init__(self, name): Backend.__init__(self, name, '.diff.png') self._pdftoppm = os.path.join(self._utilsdir, 'pdftoppm')
def validate_backend(form, field): """Validate that the backend is supported""" if not Backend.get_backend(field.data): raise ValidationError('Not a supported backend.')
def __init__(self, name): Backend.__init__(self, name, '.diff.png') self._pdftoppm = os.path.join(self._utilsdir, 'pdftoppm');
def __init__(self, name): Backend.__init__(self, name) self._pdftotext = os.path.join(self._utilsdir, 'pdftotext')
def main(): """ """ # Note: Default values for options are defined on # configuration module usage = 'Usage: %prog [options]' try: Config.set_config_options(usage) except (ErrorLoadingConfig, InvalidConfig), e: printerr(str(e)) sys.exit(2) try: backend = Backend.create_backend(Config.backend) except ImportError, e: printerr("Backend ''" + Config.backend + "'' not exists. " + str(e)) sys.exit(2) printdbg("Bicho object created, options and backend initialized") backend.run() if Config.logtable: try: ilogger = IssueLogger.create_logger(Config.backend) except ImportError, e: printerr("Logger ''" + Config.backend + "'' doesn't exist. " + str(e)) sys.exit(2) printdbg("Bicho logger object created") ilogger.run()
def __init__(self, name): Backend.__init__(self, name, ".diff.png") self._pdftoppm = os.path.join(self._utilsdir, "pdftoppm")
def __init__(self, name): Backend.__init__(self, name, '.diff') self._pdftotext = os.path.join(self._utilsdir, 'pdftotext');