def dataFits(_data: str): qr = QRCode() qr.add_data(_data) try: qr.best_fit() return True except exceptions.DataOverflowError: return False
def initialize(self): self.logNotify("Initializing OpenSelery") self.seleryPackageInfo = os_utils.getPackageInfo("openselery") if self.seleryPackageInfo: self.log("OpenSelery version [%s]" % self.seleryPackageInfo["version"]) else: # when project is executed locally without installation, seleryPackageInfo is empty self.log("OpenSelery version [undefined]") self.log("Preparing Configuration") # find all configs in potentially given config directory foundConfigs = [] if self.config.config_dir: for root, dirs, files in os.walk(self.config.config_dir): for f in files: ext = os.path.splitext(f)[1] if ext == ".yml" or ext == ".yaml": foundConfigs.append(os.path.join(root, f)) # group all found configs together with individually given configuration paths from user on top self.config.config_paths = foundConfigs + self.config.config_paths # apply yaml config to our configuration if possible self.log("Loading configurations" % self.config.config_paths) [print(" -- %s" % path) for path in self.config.config_paths] [self.loadYaml(path) for path in self.config.config_paths] # finalize our configuration settings self.config.finalize() # load the README file and check if wallet address for donation matches the configured wallet address. Before payout this address is also matched against the address of the coinbase user extractor = URLExtract() fundingPath = self._getFile("README.md") if fundingPath is not None: self.log("Loading funding file [%s] for bitcoin wallet" % fundingPath) mdfile = open("README.md", "r") mdstring = mdfile.read() urls = extractor.find_urls(mdstring) badge_string = "https://badgen.net/badge/OpenSelery-Donation/" for url in urls: if badge_string in url: self.config.bitcoin_address = url.split(badge_string, 1)[1] self.log("Found bitcoin address [%s]" % self.config.bitcoin_address) else: self.log( "Using bitcoin address from configuration file for validation check [%s]" % self.config.bitcoin_address ) # Create a new QR code based on the configured wallet address self.log("Creating QR code PNG image for funders") wallet_qrcode = QRCode(error_correction=1) wallet_qrcode.add_data(self.config.bitcoin_address) wallet_qrcode.best_fit() wallet_qrcode.makeImpl(False, 6) wallet_image = wallet_qrcode.make_image() wallet_image.save( os.path.join(self.config.result_dir, "public", "wallet_qrcode.png") ) # load tooling url if self.config.include_tooling_and_runtime and self.config.tooling_path: with open(self.config.tooling_path) as f: self.config.toolrepos = yaml.safe_load(f) if self.config.toolrepos is not None: self.log("Tooling file loaded [%s]" % self.config.toolrepos) else: self.log("No tooling urls found") else: self.log("Tooling not included") # load our environment variables self.loadEnv() self.logNotify("Initialized") self.log(str(self.getConfig()))