def test_remove_empty_player(self): app = App() response = app.remove_player(None) self.assertFalse(response.ok) self.assertEqual('The player name can\'t be empty.', response.message)
def _read(self): """ Read the json file and parse it. """ from src.app import App do_later = ["app_path", "icons_path", "icons"] try: with open(self._db_file, 'r') as db_obj: data = json.load(db_obj) for key, value in data.items(): if key not in do_later: setattr(self, key, value) except (FileNotFoundError, ValueError, KeyError): Logger.error("Application file is broken: {}".format( self._db_file)) self._parse_paths(data["app_path"], "app_path") self._parse_paths(data["icons_path"], "icons_path") self._parse_icons(data["icons"]) if len(App.get("only")) == 1 and App.path(): self.app_path.append(App.path()) found = self.icons and self.app_path if self.force_create_folder and found: for icon_path in self.icons_path: create_dir(str(icon_path)) self.dont_install = False else: self.dont_install = not (found and self.icons_path) # NWJS special case if self.get_type() == "nwjs" and not self.dont_install: self.dont_install = not App.get("nwjs")
def _read(self): """Get the theme icon,extensions and size. Save all of that to icon.""" from src.app import App if isinstance(self.icon_data, str): orig_icon = theme_icon = self.icon_data else: orig_icon = self.icon_data["original"] theme_icon = self.icon_data["theme"] base_name = path.splitext(theme_icon)[0] theme = Icon.get_theme(orig_icon) theme_icon = theme.lookup_icon(base_name, App.icon_size(), 0) if theme_icon: self.original = orig_icon self.theme = theme_icon.get_filename() self.theme_ext = get_extension(self.theme) self.orig_ext = get_extension(orig_icon) self.icon_size = self.get_icon_size(App.icon_size()) self._exists = True if (not isinstance(self.icon_data, str) and self.icon_data.get("symlinks")): symlinks = get_iterated_icons(self.icon_data["symlinks"]) # Make sure that symlinks have the right extension for symlink in symlinks: if not get_extension(symlink): symlink += ".{0}".format(self.theme_ext) self.symlinks.append(symlink)
def test_remove_nonexistent_player(self): app = App() reponse = app.remove_player('Rafael') self.assertFalse(reponse.ok) self.assertEqual('Rafael not in the list', reponse.message)
def main(): attach_logger_to_stdout() if _download_necessary_files() == False: return q_app = QtWidgets.QApplication(sys.argv) app = App() app.display_main_menu() sys.exit(q_app.exec())
def test_remove_player_successfully(self): app = App() reponse = app.add_player('Rafael') response = app.remove_player('Rafael') self.assertTrue(reponse.ok) self.assertEqual('Rafael was succesfully removed.', response.message)
def test_add_player_succesfully(self): app = App() reponse = app.add_player('Rafael') self.assertTrue(reponse.ok) self.assertEqual('Rafael successfully added.', reponse.message) self.assertTrue('Rafael' in app.players)
def test_add_player_duplicated(self): app = App() app.add_player('Rafael') reponse = app.add_player('Rafael') self.assertFalse(reponse.ok) self.assertEqual( 'Rafael already in the players list.', reponse.message)
def run(self): running = True while running: app = App(self.args) app.init(self.ai_controllers) self.ai_controllers = app.ai_controllers should_exit = app.run() running = not should_exit
def test(): import json import uuid from src.app import App, source from cn_search_py.connect import (setup_indexes, get_connection as get_search_connection) from cn_search_py.collections import ItemCollection app = App("transform", pipeline_steps = default_tasks) random_id = str(uuid.uuid4()) data = { 'remoteID': random_id, 'content': "U.S. aerial intervention against ISIS could give the upper hand to Iraqi security forces on the ground. But air power alone won't decide the battle against the jihadist group, says Karl Mueller. http://on.rand.org/yc6jH", 'source': "facebook", 'image': 'https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-xap1/t1.0-0/10436089_642636699158835_6716614903784028712_s.jpg', 'fromURL': "http://www.theage.com.au/world/taliban-attackers-mistake-armed-contractors-for-christian-daycare-workers-20140330-zqolw.html", 'summary': "U.S. aerial intervention against ISIS could give the upper hand to Iraqi security forces on the ground. But air power alone won't decide the battle against the jihadist group, says Karl Mueller. http://on.rand.org/yc6jH", 'license': "unknown", 'language': { 'code': "en", 'name': "English", 'nativeName': "English" }, 'tags': [ { 'name': "Christianity", 'confidence': 1 }, { 'name': "deportation", 'confidence': 1 }, { 'name': "conflict", 'confidence': 1 } ], 'geo': { 'addressComponents': { 'formattedAddress': "Kabul, Kabol, Afghanistan" } }, 'lifespan': "temporary" } item = app.item_collection.make_model(data) saved = item.save(refresh=True) app.work(json.dumps({"id":str(saved['_id'])})) doc = source(app.item_collection, saved['_id'])() assert doc['remoteID'] == random_id assert 'Iraqi' in doc['entities'] assert 'photo-person' in [tag['name'] for tag in doc['tags']]
def main() -> int: start = now() parser = argparse.ArgumentParser(description='Display subtitles from file') parser.add_argument('file', type=str, help='file path') options = parser.parse_args() subs = Subs(options.file) try: subs.process() except SubsFileNotFound: return 1 app = App(start, subs) return app.run()
def get_theme(icon_name): """Get the theme to be used dark or light.""" from src.app import App if isinstance(App.theme(), dict): is_dark = "dark" in icon_name.lower() if is_dark: theme = App.theme()["dark"] else: theme = App.theme()["light"] else: theme = App.theme() return theme
def test_list_three_players(self): app = App() app.add_player('Rafael') app.add_player('Simão') app.add_player('Rodrigo') response = app.list_players() self.assertTrue(response.ok) self.assertEqual(3, len(response.data['players']))
def pack(self, icon_path): """Recreate the zip file from the tmp directory.""" from src.app import App nwjs_sdk = App.get("nwjs") if nwjs_sdk: binary_file = "/tmp/{0}".format(self.binary) execute(["npm", "install"], True, True, self.tmp_path) make_archive(binary_file, "zip", self.tmp_path) move(binary_file + ".zip", binary_file + ".nw") local_binary_file = path.join(nwjs_sdk, self.binary) move(binary_file + ".nw", local_binary_file + ".nw") execute(["cat which nw " + self.binary + ".nw > " + self.binary], True, True, nwjs_sdk) remove(local_binary_file + ".nw") move(local_binary_file, path.join(str(icon_path), self.binary)) execute(["chmod", "+x", path.join(str(icon_path), self.binary)]) rmtree(self.tmp_path)
def main(): # Initialize the app and the shell using the configuration data app = App(cache_folder=CACHE_FOLDER, database_folder=DATABASE_FOLDER) # Create all the necessary folders app.cache.init() # Initialize the shell and run it with the given arguments load_shell(app=app, style=style).run(argv)
def get_pngbytes(icon): """Return the pngbytes of a svg/png icon.""" from src.app import App icon_for_replace = icon.theme icon_extension = icon.theme_ext icon_size = icon.icon_size if icon_extension == 'svg': if icon_size != App.icon_size(): png_bytes = App.svg().to_bin(icon_for_replace, App.icon_size()) else: png_bytes = App.svg().to_bin(icon_for_replace) elif icon_extension == "png": with open(icon_for_replace, 'rb') as png_file: png_bytes = png_file.read() else: png_bytes = None return png_bytes
def delete(self, request): session = App.get_db().session try: self._service.delete( self._entity_adapter.to_dto_from_request(request)) session.commit() session.flush() return jsonify([]), 204 except Exception as exception: session.rollback() raise exception
def main(): parser = argparse.ArgumentParser() parser.add_argument("--model", default="assets/models/cnn_113_80_quantized.tflite") parser.add_argument("--checkpoint", action="store_true") parser.add_argument("--large", action="store_true") args = parser.parse_args() from load_model import load_any_model_filepath model, (HEIGHT, WIDTH) = load_any_model_filepath(args.model, not args.checkpoint, args.large) # screen box is (x, y, width, height) bounding_box = (677, 289, 322, 455) app = App() app.bounding_box = bounding_box callback = ImageCallback(*bounding_box[2:4]) app.image_callback = callback.on_image screenshotter = MSSScreenshot() # screenshotter = D3DScreenshot() predictor = Predictor(model, (HEIGHT, WIDTH)) predictor.acceleration = 2.5 def on_press(key): if key == Key.f1: print("[Resumed]") app.is_paused = False elif key == Key.f2: print("[Paused]") app.is_paused = True elif key == Key.f3: print("[Exit]") app.stop() # callback.stop_threads() elif key == Key.f4: callback.is_preview = not callback.is_preview print(f"[Preview={callback.is_preview}]") elif key == Key.f5: app.show_debug = not app.show_debug print("[Debug={0}]".format(app.show_debug)) elif key == Key.f6: app.track_only = not app.track_only print("[Track={0}]".format(app.track_only)) elif key == Key.f7: callback.is_recording = not callback.is_recording print(f"[Recording={callback.is_recording}]") input_listener = Listener(on_press=on_press) input_listener.start() display_controls() callback.start_threads() app.start(predictor, screenshotter) input_listener.stop() callback.stop_threads()
def main(): # First we created a application object for pyqt app = QApplication(sys.argv) # Then we apply Flatipie style sheet and modern window style for creating modern-looking interfaces. # Please note that this is important for creating flatipie style app. apply_palette(app) window = ModernWindow(App()) # Next is we show the window then execute the app. window.show() sys.exit(app.exec_())
def create(self, request): session = App.get_db().session try: entity = self._service.create( self._entity_adapter.to_dto_from_request(request)) session.commit() session.flush() response = self._entity_adapter.to_response_data_from_entity( entity) return jsonify(response), 201 except Exception as exception: session.rollback() raise exception
def create(self, filename): """Backup functions.""" from src.app import App if not App.get("backup_ignore"): if not self.backup_dir: self.create_backup_dir() backup_file = path.join(self.backup_dir, path.basename(filename)) if path.exists(filename): Logger.debug("Backup file: {0} to: {1}".format( filename, backup_file)) copy_file(filename, backup_file, True) mchown(backup_file)
def handle_error(exception): code = 500 if isinstance(exception, ImproveDomainException): if isinstance(exception, EntityNotFoundException): code = 404 elif isinstance(exception, BaseSecurityException): code = 403 elif isinstance(exception, EntityValidationException): code = 422 return jsonify(errors=exception.get_errors(), message=exception.get_message()), code if App.is_production_env(): return jsonify(message='Unknown error'), code raise exception
def _validate(self): """ Check wether a folder path exists or not. """ from src.app import App Path.DB_VARIABLES["{size}"] = str(App.icon_size()) for key, value in Path.DB_VARIABLES.items(): if key in self.path: if value.endswith( "_callback"): # Check wether it's a function or not self._validate_with_callback(key, value) else: self.path = self.path.replace(key, str(value)) if self.parser.script and self.type == "icons_path": binary_file = path.join(self.path, self.parser.binary) self._exists = path.exists(self.path) and path.exists(binary_file) else: self._exists = path.exists(self.path)
def install_icon(self, icon, icon_path): """Install icon to the current directory.""" ext_orig = icon.orig_ext theme_icon = icon.theme ext_theme = icon.theme_ext icon_size = icon.icon_size output_icon = path.join(str(icon_path), icon.original) # Backup the output_icon if not self.backup_ignore: self.backup.create(output_icon) if ext_theme == ext_orig: if theme_icon != output_icon: symlink_file(theme_icon, output_icon) elif ext_theme == "svg" and ext_orig == "png": from src.app import App if icon_size != App.icon_size(): App.svg().to_png(theme_icon, output_icon, App.icon_size()) else: App.svg().to_png(theme_icon, output_icon) mchown(output_icon)
def main(): app = App() app.run()
from src.app import App if __name__ == "__main__": App.run(host='0.0.0.0', port=7000, debug=True)
def init_app(self): app = App() app.do_routine() if env.HAS_ROUTINE: app.start_routine()
import json from bson import ObjectId from flask import request from flask_cors import CORS from werkzeug.exceptions import abort from src.app import App # app = Flask(__name__) # CORS(app) app = App() CORS(app.flask) # run the application that does database manipulation def route(): return app.flask @app.flask.route("/api/v1/company", methods=["POST"]) def create_company(): if not request.json or 'name' not in request.json: abort(400) # company = Company(**request.json) # print(company) # company = { # 'type': request.json['type'], # 'name': request.json['name'], # 'address': request.json['address'],
""" @package main @author andresgonzalezfornell Main module to run the application. """ from lib.appJar.appjar import gui from src.app import App gui = gui() gui.setImageLocation("res") gui.setIcon("airplane.gif") app = App(gui)
help=_("print the version number of Hardcode-Tray.")) parser.add_argument("--apply", "-a", action='store_true', help=_("fix hardcoded tray icons")) parser.add_argument("--revert", "-r", action='store_true', help=_("revert fixed hardcoded tray icons")) parser.add_argument("--conversion-tool", "-ct", help=_("Which of conversion tool to use"), type=str, choices=ConversionTools.choices()) parser.add_argument('--change-color', "-cc", type=str, nargs='+', help=_("Replace a color with an other one, " "works only with SVG.")) parser.add_argument("--clear-cache", action="store_true", help=_("Clear backup files")) args = parser.parse_args() App.set_args(args) if (not DESKTOP_ENV or DESKTOP_ENV == "other") and not App.icon_size(): exit(_("You need to run the script using 'sudo -E'.\nPlease try again")) print(_("Welcome to Hardcode-Tray!")) print(_("Desktop Environment: {}").format(DESKTOP_ENV.title())) print(_("Scaling Factor: {}").format(App.scaling_factor())) print(_("Icon Size: {}").format(App.icon_size())) if not isinstance(App.theme(), dict): print(_("Icon Theme: {}").format(App.theme())) else: print(_("Dark Icon Theme: {}").format(App.theme("dark"))) print(_("Light Icon Theme: {}").format(App.theme("light"))) print(_("Conversion Tool: {}").format(App.svg())) print(_("To Do: "), end="")
from src.app import App if __name__ == "__main__": main_app_window = App(900, 684) main_app_window()
from src.app import App import sys App().start()