コード例 #1
0
    def post(self):
        self.check_access()
        args = parser.parse_args(strict=True)

        if args.get('enable') == 0:
            cert_root = self.root + "/config/certificates/"
            self.config.get('data').get('security').get('ssl')['enabled'] = 0
            Utils.save_file(self.root + "/config/config.json",
                            self.config.get('data'))
            open("/tmp/.flenginerestart", "w").write("restart")
            func = request.environ.get('werkzeug.server.shutdown')
            func()
        elif args.get('enable') == 1:
            client = None

            if not args.get('client') or not args.get('id'):
                abort(400, message="invalid payload")

            try:
                client = base64.b64decode(args.get('client'))
            except Exception, ex:
                abort(400, message="failed to decode payload: " % str(ex))

            rc = True
            try:
                rc = self.create_certificate(args.get('id'))
            except Exception, ex:
                abort(400, message="failed to create engine certificate: %s" %\
                           str(ex))
コード例 #2
0
ファイル: ResourceInitAcl.py プロジェクト: wxh0000mm/FuzzLabs
    def get(self):
        client = request.remote_addr

        # If for whatever reason we do not have a security key
        # it will be created here.

        if not self.config.get('data').get('security'):
            self.config.get('data')['security'] = {}

        # Check ACL. If there is not one, create one.

        allow = self.config.get('data').get('security').get('allow')
        if not allow:
            allow = self.config.get('data')['security']['allow'] = []

        if len(allow) > 0:
            abort(403, message="ACL already initialized")

        self.config.get('data')['security']['allow'].append({
            "address": client
        })

        # Save changes

        Utils.save_file(self.root + "/config/config.json",
                        self.config.get('data'))

        # And return the API key to the client

        return {"message": "success"}, 200
コード例 #3
0
    def init_library(self):
        max = Utils.bin_to_dec("1" + "0" * 8) - 1  # 8 bits
        if self.signed: max = max / 2

        if self.max_num and self.max_num > max:
            raise Exception("%s primitive maximum value is %d" %
                            (self.type, max))
        if self.max_num == None or self.max_num == 0:
            self.max_num = max

        if self.full_range:
            for i in xrange(0, self.max_num + 1):
                if i not in self.library: self.library.append(i)
        else:
            self.library += Utils.integer_boundaries(self.library,
                                                     self.max_num, 0)
            self.library += Utils.integer_boundaries(self.library,
                                                     self.max_num,
                                                     self.max_num)
            for v in [2, 3, 4, 8, 16, 32]:
                self.library += Utils.integer_boundaries(
                    self.library, self.max_num, self.max_num / v)

        negatives = []
        if self.signed:
            for v in self.library:
                negatives.append(-v)
        self.library += negatives
コード例 #4
0
    def __init__(self,
                 camera_height=None,
                 hand=None,
                 skeleton=None,
                 depth_map=None,
                 image=None,
                 type=None,
                 distance=None,
                 target=None):
        self.settings = Settings()
        self.utils = Utils()

        # Initialise each attributes with respective parameters; otherwise with a default value
        if camera_height is None:
            camera_height = 1500
        self.camera_height = camera_height

        if hand is None:
            hand = self.settings.LEFT_HAND
        self.hand = hand

        if skeleton is None:
            skeleton = {
                "head": [],
                "shoulder": {
                    "left": [],
                    "right": [],
                    "center": []
                },
                "elbow": {
                    "left": [],
                    "right": []
                },
                "hand": {
                    "left": [],
                    "right": []
                }
            }
        self.skeleton = skeleton

        if depth_map is None:
            depth_map = []
        self.depth_map = np.array(depth_map)

        if image is None:
            image = ""
        self.image = image

        if type is None:
            type = Dataset.TYPE_POSITIVE
        self.type = type

        if distance is None:
            distance = Dataset.DISTANCE_550
        self.distance = distance

        if target is None:
            target = []
        self.target = target
コード例 #5
0
    def create_train_test_valid_folders(dataset_train_test_valid_directory,
                                        dataset_folders_to_create,
                                        dataset_classes):
        for dirname in dataset_folders_to_create:
            Utils.create_folder_if_not_exists(
                os.path.join(dataset_train_test_valid_directory, dirname))

            for class_name in dataset_classes:
                Utils.create_folder_if_not_exists(
                    os.path.join(dataset_train_test_valid_directory, dirname,
                                 class_name))
コード例 #6
0
ファイル: ResourceAclAdd.py プロジェクト: wxh0000mm/FuzzLabs
    def post(self):
        self.check_access()
        args = parser.parse_args(strict=True)
        if self.is_allowed(args['address']):
            return {"message": "access is already granted"}, 200

        self.config.get('data').get('security').get('allow').append(
            {"address": args['address']})
        Utils.save_file(self.root + "/config/config.json",
                        self.config.get('data'))
        return {"message": "success"}, 200
コード例 #7
0
    def init_library(self):
        max = Utils.bin_to_dec("1" + "0" * (self.get('size') * 8)) - 1

        if self.full_range:
            for i in xrange(0, max + 1):
                if i not in self.library: self.library.append(i)
        else:
            self.library += Utils.integer_boundaries(self.library, max, 0)
            self.library += Utils.integer_boundaries(self.library, max, max)
            for v in [2, 3, 4, 8, 16, 32]:
                self.library += Utils.integer_boundaries(
                    self.library, max, max / v)
コード例 #8
0
ファイル: ResourceRemove.py プロジェクト: wxh0000mm/FuzzLabs
    def get(self):
        self.check_access()
        args = parser.parse_args(strict=True)
        self.config.get('data').get('security').pop('allow')
        self.config.get('data').get('security').pop('apikey')
        Utils.save_file(self.root + "/config/config.json",
                        self.config.get('data'))

        if args.get('terminate') == "true":
            func = request.environ.get('werkzeug.server.shutdown')
            func()

        return {"message": "success"}, 200
コード例 #9
0
ファイル: include.py プロジェクト: wxh0000mm/FuzzLabs
    def __init__(self, properties, parent=None):
        global all_properties
        __primitive__.__init__(self, properties, all_properties, parent)
        self.completed = False

        unit = Utils.read_json(Utils.getRoot() + "/units/" + self.unit +
                               ".json")
        self.load_primitives(unit.get('primitives'))

        lmod = importlib.import_module("logic." + self.logic[0].upper() +\
                                       self.logic[1:])
        self.logic = getattr(lmod,
                             self.logic[0].upper() + self.logic[1:])(self)
コード例 #10
0
    def start(cli):
        token = cli.get_secure_cookie('token').decode('UTF-8') if(cli.get_secure_cookie('token') is not None) else None
        if token:
            try:
                Sessions.delete().where(Sessions.last_active <= datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
                db_sess = Sessions.get(Sessions.session_key == token)
            except peewee.DoesNotExist:
                db_sess = None
            except Exception as e:
                print('Get current session from DB Error:', e.__str__())
                db_sess = None

            if db_sess is None:
                print('crt_sess if no in DB ->>')
                sess = Session.create_session({})
                cli.set_secure_cookie('token', sess.sess_token)
            else:
                print('Get sess from DB:', db_sess.session_key)
                sess = Session.restore_session(db_sess.session_key, Utils.convert_json_to_dict(db_sess.session_data))
        else:
            print('crt_sess ->>')
            sess = Session.create_session({})
            cli.set_secure_cookie('token', sess.sess_token, 1)

        sess.update_session()
        print('Token', sess.sess_token)
        print('Sess Data:', sess.sess_data)
        return sess
コード例 #11
0
    def train_models(dataset_dataloader, dataset_test_dir_name,
                     dataset_train_dir_name, dataset_valid_dir_name,
                     training_cnn_models_to_train, training_criterion,
                     training_dropout, training_epochs_early_stopping,
                     training_epochs_count, training_feature_extract,
                     training_learning_rate, training_lr_gamma,
                     training_lr_step_size, training_model_output_directory,
                     training_momentum, training_optimizer,
                     training_save_best_model_enabled, training_scheduler,
                     training_use_gpu, training_use_early_stopping,
                     training_use_pretrained_models, training_use_softmax,
                     training_weight_decay, signals):
        for i, model_id in enumerate(training_cnn_models_to_train):
            signals['label_training_model_name_text_changed'].emit(model_id)
            signals['console_append'].emit('----------\n' + model_id +
                                           '\n----------')

            model, accuracy_loss_history = ModelTraining.train_model(
                model_id=model_id,
                dataset_dataloader=dataset_dataloader,
                dataset_test_dir_name=dataset_test_dir_name,
                dataset_train_dir_name=dataset_train_dir_name,
                dataset_valid_dir_name=dataset_valid_dir_name,
                training_criterion=training_criterion,
                training_dropout=training_dropout,
                training_epochs_count=training_epochs_count,
                training_epochs_early_stopping=training_epochs_early_stopping,
                training_use_gpu=training_use_gpu,
                training_use_early_stopping=training_use_early_stopping,
                training_feature_extract=training_feature_extract,
                training_learning_rate=training_learning_rate,
                training_lr_gamma=training_lr_gamma,
                training_lr_step_size=training_lr_step_size,
                training_momentum=training_momentum,
                training_optimizer=training_optimizer,
                training_scheduler=training_scheduler,
                training_use_pretrained_models=training_use_pretrained_models,
                training_use_softmax=training_use_softmax,
                signals=signals,
                training_weight_decay=training_weight_decay)

            if training_save_best_model_enabled:
                path = Utils.create_folder_if_not_exists(
                    training_model_output_directory)
                ModelIO.save(
                    model=model,
                    model_id=model_id,
                    output_dir=path,
                    classes=dataset_dataloader[dataset_train_dir_name].dataset.
                    classes,
                    feature_extract=training_feature_extract,
                    use_pretrained=training_use_pretrained_models,
                    training_dropout=training_dropout,
                    training_use_softmax=training_use_softmax)

            signals['plot_train_valid_acc_loss_graph'].emit(
                accuracy_loss_history, model_id)
            signals['progressBar_training_set_value_changed'].emit(
                (i + 1) / len(training_cnn_models_to_train) * 100)
コード例 #12
0
 def set_listWidget_testing_dataset_class_name(self):
     self.listWidget_testing_dataset_class_name.addItems(
         Utils.list_folders(
             self.app_model.model['testing_dataset_test_directory']))
     self.listWidget_testing_dataset_class_name.setSelectionMode(
         QListWidget.ExtendedSelection)
     self.listWidget_testing_dataset_class_name.itemSelectionChanged.connect(
         self.listWidget_testing_dataset_class_name_selection_changed)
コード例 #13
0
    def post(self):
        found = False
        self.check_access()
        args = parser.parse_args(strict=True)
        cnt = 0
        for allowed in self.config.get('data').get('security').get('allow'):
            if allowed.get('address') == args['address']:
                self.config.get('data').get('security').get('allow').pop(cnt)
                found = True
                break
            cnt += 1

        if not found:
            abort(404, message="address not found in ACL")

        Utils.save_file(self.root + "/config/config.json",
                        self.config.get('data'))
        return {"message": "success"}, 200
コード例 #14
0
 def toolbutton_testing_saved_models_directory_clicked(self):
     path = str(
         QFileDialog.getExistingDirectory(
             self, "Select Directory",
             self.app_model.model['testing_saved_models_directory']))
     self.app_model.set_to_model('testing_saved_models_directory', path)
     self.lineedit_testing_saved_models_directory.setText(path)
     models_in_dir = Utils.list_files_with_extensions(path, ['.pth'])
     self.listWidget_testing_saved_models.clear()
     self.listWidget_testing_saved_models.addItems(models_in_dir)
コード例 #15
0
 def toolbutton_testing_dataset_test_directory_clicked(self):
     path = str(
         QFileDialog.getExistingDirectory(
             self, "Select Directory",
             self.app_model.model['testing_dataset_test_directory']))
     self.app_model.set_to_model('testing_dataset_test_directory', path)
     self.lineedit_testing_dataset_test_directory.setText(path)
     self.listWidget_testing_dataset_class_name.clear()
     self.listWidget_testing_dataset_class_name.addItems(
         Utils.list_folders(path))
コード例 #16
0
 def load_unit(self, unit):
     data = None
     u_path = self.config.get('root') + "/units/" + unit + ".json"
     u_path = os.path.dirname(
         os.path.abspath(inspect.getfile(
             inspect.currentframe()))) + "/../../units/" + unit + ".json"
     try:
         data = Utils.read_json(u_path)
     except Exception, ex:
         raise Exception("failed to read unit '%s': %s" % (unit, str(ex)))
コード例 #17
0
    def get(self):

        # If for whatever reason we do not have a security key
        # it will be created here.

        if not self.config.get('data').get('security'):
            abort(500, message="invalid configuration")

        # Check ACL

        allow = self.config.get('data')['security'].get('allow')
        if not allow:
            abort(500, message="invalid configuration")
        allowed = False
        if allow:
            allowed = False
            for c in allow:
                if c.get('address') and c.get('address') == request.remote_addr:
                    allowed = True
        if not allowed:
            abort(403, message="access blocked due to ACL")

        # Check API key. If there is one set we return error here.

        apikey = self.config.get('data').get('security').get('apikey')
        if apikey and len(apikey) > 0:
            abort(403, message="api key already set")

        # If there was no API key set we generate a new one here.

        if not apikey or len(apikey) == 0:
            apikey = Utils.generate_name()
            self.config.get('data')['security']['apikey'] = apikey

        # Finally, we save the updated configuration

        Utils.save_file(self.root + "/config/config.json",
                        self.config.get('data'))

        # And return the API key to the client

        return {"message": "success", "apikey": apikey}, 200
コード例 #18
0
	def __init__(self, camera_height=None, hand=None, skeleton=None, depth_map=None, image=None, type=None, distance=None, target=None):
		self.settings = Settings()
		self.utils = Utils()
		
		# Initialise each attributes with respective parameters; otherwise with a default value
		if camera_height is None:
			camera_height = 1500
		self.camera_height = camera_height
		
		if hand is None:
			hand = self.settings.LEFT_HAND
		self.hand = hand
		
		if skeleton is None:
			skeleton = {
				"head": [],
				"shoulder": {
					"left": [],
					"right": [],
					"center": []
				},
				"elbow": {
					"left": [],
					"right": []
				},
				"hand": {
					"left": [],
					"right": []
				}
			}
		self.skeleton = skeleton
		
		if depth_map is None:
			depth_map = []
		self.depth_map = np.array(depth_map)
		
		if image is None:
			image = ""
		self.image = image
		
		if type is None:
			type = Dataset.TYPE_POSITIVE
		self.type = type
		
		if distance is None:
			distance = Dataset.DISTANCE_550
		self.distance = distance
		
		if target is None:
			target = []
		self.target = target
コード例 #19
0
    def __init__(self, properties, all_properties=None, parent=None):
        self.parent = parent
        self.iter_cnt = 0
        self.rendered = ""
        self.completed = False
        self.library = []
        self.primitives = []
        self.mutation_index = 0
        self.total_mutations = 0
        self.type = properties.get('primitive')

        properties = properties.get('properties')
        if not properties:
            raise Exception('missing properties for primitive')

        self.transforms = properties.get('transforms')

        # Set up properties that were provided in the grammar
        for prop in properties:
            for primitive_prop in all_properties:
                if prop == primitive_prop.get('name'):
                    p = Property(prop, properties[prop], primitive_prop)
                    self[prop] = p.value
                    del p

        # Set up defaults for properties that were not included
        props_provided = self.get_properties(properties)
        for prop in all_properties:
            if prop.get('name') not in props_provided:
                p = Property(prop.get('name'), prop.get('default'), prop)
                self[prop.get('name')] = p.value
                del p

        if not self.get('name'):
            self['name'] = Utils.generate_name()

        if self.transforms:
            for transform in self.transforms:
                if transform.get('apply') == "before":
                    self.value = self.apply_transforms(self.value)

        # First item in library is the original value
        if self.get('value'): self.library.append(self.value)

        if self.get('fuzzable'):
            self.init_library()
            self.total_mutations = len(self.library)
        else:
            self.completed = True
コード例 #20
0
ファイル: Worker.py プロジェクト: wxh0000mm/FuzzLabs
    def __init__(self, logger, config, uuid, job):
        threading.Thread.__init__(self)
        self.logger    = logger
        self.config    = config
        self.id        = uuid
        self.job       = None
        self.driver    = None
        self.scenarios = []

        try:
            self.job = Utils.read_json(job)
        except Exception, ex:
            msg = self.logger.log("failed to initialize job", "error",
                            str(ex),
                            self.id,
                            job)
            raise Exception(msg)
コード例 #21
0
ファイル: ModelIO.py プロジェクト: Peto-RS/DP_CNN
    def save(model, output_dir, model_id, classes, feature_extract,
             use_pretrained, training_dropout, training_use_softmax):
        output_dir = Utils.create_folder_if_not_exists(output_dir)

        filename = model_id + DELIMITER + datetime.now().strftime(
            "%Y%m%d_%H%M%S") + '.pth'
        torch.save(model, os.path.join(output_dir, filename))
        torch.save(
            {
                'classes': classes,
                'feature_extract': feature_extract,
                'model_id': model_id,
                'model_state_dict': model.state_dict(),
                'use_pretrained': use_pretrained,
                'training_dropout': training_dropout,
                'training_use_softmax': training_use_softmax
            }, os.path.join(output_dir, filename))
コード例 #22
0
ファイル: ModelEvaluation.py プロジェクト: Peto-RS/DP_CNN
    def train_valid_acc_loss_graph(history, model_name, save,
                                   training_evaluation_directory):
        history = pd.DataFrame(
            history,
            columns=['train_acc', 'train_loss', 'valid_acc', 'valid_loss'])

        fig = plt.figure(figsize=(15, 6))
        locator = matplotlib.ticker.MultipleLocator(1)
        fig.suptitle(model_name)

        subfig = fig.add_subplot(122)
        fig.gca().xaxis.set_major_locator(locator)
        subfig.plot(history['train_acc'], label="Training")
        subfig.plot(history['valid_acc'], label="Validation")
        subfig.set_title('Model Accuracy')
        subfig.set_xlabel('Epoch')
        subfig.set_ylabel('Percentage')
        subfig.legend(loc='upper left')

        subfig = fig.add_subplot(121)
        fig.gca().xaxis.set_major_locator(locator)
        subfig.plot(history['train_loss'], label="Training")
        subfig.plot(history['valid_loss'], label="Validation")
        subfig.set_title('Model Loss')
        subfig.set_xlabel('Epoch')
        subfig.set_ylabel('Loss')
        subfig.legend(loc='upper right')

        plt.show()

        if save:
            path = os.path.join(training_evaluation_directory, model_name)
            path = Utils.create_folder_if_not_exists(path)

            plt.savefig(os.path.join(
                path, 'valid_acc_loss_graph_' +
                datetime.now().strftime("%Y%m%d_%H%M%S") + '.png'),
                        bbox_inches='tight')
コード例 #23
0
ファイル: Config.py プロジェクト: wxh0000mm/FuzzLabs
 def save(self):
     Utils.save_file(self.root + "/config/config.json",
                     self.data,
                     True)
コード例 #24
0
ファイル: Config.py プロジェクト: wxh0000mm/FuzzLabs
 def __init__(self, root, filename):
     self.root = root
     self.data = Utils.read_json(root + filename)
コード例 #25
0
 def prepare_request_body(req_body):
     return Utils.convert_json_to_dict(req_body.decode("UTF-8"))
コード例 #26
0
class Dataset:
    TYPE_POSITIVE = 0
    TYPE_NEGATIVE = 1
    TYPE_ACCURACY = 2
    TYPE_HEATMAP = 3

    LEFT_HAND = 0
    RIGHT_HAND = 1
    NO_HAND = 2

    DISTANCE_550 = 0
    DISTANCE_750 = 4
    DISTANCE_1000 = 1
    DISTANCE_1250 = 5
    DISTANCE_1500 = 2
    DISTANCE_1750 = 6
    DISTANCE_2000 = 3

    # Constructor of the Dataset class
    #
    # @param	camera_height		Value of the camera height while gathering informations
    # @param	hand				Identifier of the hand (Ø|1|2)
    # @param	skeleton			Skeletal joints of the detected subject
    # @param	depth_map			Depth map of the captured scene
    # @param	image				RGB image of the captured scene
    # @param	type				Identifier of the type of data (0|1|2|3)
    # @param	distance			Identifier of the type of distance chosen (0|1|2|3|4|5|6) or the actual distance between the fingertip and the target
    # @param	target				Coordinates of the target
    # @return	None
    def __init__(self,
                 camera_height=None,
                 hand=None,
                 skeleton=None,
                 depth_map=None,
                 image=None,
                 type=None,
                 distance=None,
                 target=None):
        self.settings = Settings()
        self.utils = Utils()

        # Initialise each attributes with respective parameters; otherwise with a default value
        if camera_height is None:
            camera_height = 1500
        self.camera_height = camera_height

        if hand is None:
            hand = self.settings.LEFT_HAND
        self.hand = hand

        if skeleton is None:
            skeleton = {
                "head": [],
                "shoulder": {
                    "left": [],
                    "right": [],
                    "center": []
                },
                "elbow": {
                    "left": [],
                    "right": []
                },
                "hand": {
                    "left": [],
                    "right": []
                }
            }
        self.skeleton = skeleton

        if depth_map is None:
            depth_map = []
        self.depth_map = np.array(depth_map)

        if image is None:
            image = ""
        self.image = image

        if type is None:
            type = Dataset.TYPE_POSITIVE
        self.type = type

        if distance is None:
            distance = Dataset.DISTANCE_550
        self.distance = distance

        if target is None:
            target = []
        self.target = target

    # Returns a JSON encoded string of the dataset object
    #
    # @param	None
    # @return	string				JSON encoded string of the dataset object
    def to_JSON(self):
        # Convert the depth map to a serializable state
        self.depth_map = self.depth_map.tolist()

        # Encode the RGB image in a base64 string
        self.image = self.utils.getBase64(self.image)

        # Get rid of extra attributes to clean the output
        obj = deepcopy(self)
        del obj.settings
        del obj.utils

        return json.dumps(obj,
                          default=lambda o: o.__dict__,
                          separators=(',', ':'))

    # Save the dataset informations as a file
    #
    # @param	None
    # @return	None
    def save(self):
        print "Saving dataset informations..."

        # Save the dataset to the right folder
        if self.type == Dataset.TYPE_POSITIVE:
            filename = self.settings.getPositiveFolder()
        elif self.type == Dataset.TYPE_NEGATIVE:
            filename = self.settings.getNegativeFolder()
        elif self.type == Dataset.TYPE_ACCURACY:
            filename = self.settings.getAccuracyFolder()
        else:
            raise ValueError("Invalid type of dataset to save", self.type)

        # Retrieve the number of files saved so far
        # Be careful that due to the sample file, the counter does not need to be incremented. Otherwise, the files would replace each others
        filename += str(
            self.utils.getFileNumberInFolder(filename)).zfill(3) + ".json"
        self.utils.dumpJsonToFile(self.to_JSON(), filename)

    # Toggle the type identifier of the dataset
    #
    # @param	value				Identifier of the new type of the dataset
    # @return	None
    def toggleType(self, value):
        self.type = value
        print "type toggled to {0}".format(value)

    # Toggle the distance identifier of the dataset
    #
    # @param	value				Identifier of the new distance of the dataset
    # @return	None
    def toggleDistance(self, value):
        self.distance = value
        print "distance toggled to {0}".format(value)

    # Update the distance of the dataset
    #
    # @param	value				Distance value
    # @return	None
    def setDistance(self, value):
        self.distance = value
        print "distance changed to {0}".format(value)

    # Toggle the hand identifier of the dataset
    #
    # @param	value				Identifier of the new hand of the dataset
    # @return	None
    def toggleHand(self, value):
        self.hand = value
        print "hand toggled"

    # Returns the actual distance
    #
    # @param	None
    # @return	numeric				Actual distance value (translated if identifier)
    def getWishedDistance(self):
        if self.distance == Dataset.DISTANCE_550:
            return 550
        elif self.distance == Dataset.DISTANCE_750:
            return 750
        elif self.distance == Dataset.DISTANCE_1000:
            return 1000
        elif self.distance == Dataset.DISTANCE_1250:
            return 1250
        elif self.distance == Dataset.DISTANCE_1500:
            return 1500
        elif self.distance == Dataset.DISTANCE_1750:
            return 1750
        elif self.distance == Dataset.DISTANCE_2000:
            return 2000
        else:
            return self.distance
コード例 #27
0
ファイル: engine.py プロジェクト: wxh0000mm/FuzzLabs
from flask import Flask
from flask_restful import Api
from classes.Utils import Utils
from classes.Config import Config

ROOT = os.path.dirname(
            os.path.abspath(
                inspect.getfile(inspect.currentframe()
            )))
config = Config(ROOT, "/config/config.json")
endpoints = None
app = Flask(__name__)
api = Api(app)

try:
    endpoints = Utils.read_json(ROOT + "/config/endpoints.json")
except Exception, ex:
    raise Exception('failed to load endpoints configuration: %s' %\
                    str(ex))

for endpoint in endpoints:
    ep_name  = endpoint.keys()[0]
    ep_cname = endpoint[ep_name]
    ep_mod   = importlib.import_module("classes." +\
                                       ep_cname)
    ep_class = getattr(ep_mod, ep_cname)
    api.add_resource(ep_class,
                     ep_name,
                     resource_class_kwargs=config)

def start_engine():
コード例 #28
0
call(["clear"])

print('Chargement des données ...')

# On récupère les données depuis l'api instagram
instance = Auth(username, password)
connection = instance.connect()
api = Api(connection)
followers = api.getAllFollowers()
followings = api.getAllFollowings()
postsIds = api.getLastPostsIds(postsToLoad)
likes = api.getPostsLikes(postsIds)

call(['clear'])

print('---------- \n')

#On affiche le résultat des calculs dans la console
print('Personnes que vous ne suivez pas mais qui vous suivent :\n')
Utils.printPeopleNotFollowings(followers, followings, ignoreCertified)

print('---------- \n')

print('\nPersonnes que vous suivez mais qui ne vous suivent pas : \n')
Utils.printPeopleNotFollowers(followers, followings, ignoreCertified)

print('---------- \n')

print('\nAffichage des personnes selon leur nombre de likes : \n')
Utils.printFollowersLikeRatio(likes, followers, postsToLoad)
コード例 #29
0
ファイル: Worker.py プロジェクト: wxh0000mm/FuzzLabs
                                str(ex),
                                self.id,
                                self.job.get('id'),
                                scenario.get('name'))
                raise Exception(msg)

# -----------------------------------------------------------------------------
# This is just to:
#     a) be able to easily test the worker
#     b) be able to run a fuzzing job from the command line
# -----------------------------------------------------------------------------

ROOT = os.path.dirname(
            os.path.abspath(
                inspect.getfile(inspect.currentframe()
            )))
config = Config(ROOT, "/../config/config.json")
logger = Logger()

if len(sys.argv) != 2:
    print "Usage: %s <job descriptor>" % sys.argv[0]
    sys.exit(1)

w = Worker(
        logger,
        config,
        Utils.generate_name(), 
        sys.argv[1])
w.start()

コード例 #30
0
                abort(400, message="failed to set up certificates")

            cert_root = self.root + "/config/certificates/"
            self.config.get('data').get('security')['ssl'] = {}
            self.config.get('data').get('security').get('ssl')['enabled'] = 1
            self.config.get('data').get('security').get(
                'ssl')['certificate'] = cert_root + "engine.crt"
            self.config.get('data').get('security').get(
                'ssl')['key'] = cert_root + "engine.key"
            for acle in self.config.get('data').get('security').get('allow'):
                if acle.get('address') and acle.get(
                        'address') == request.remote_addr:
                    acle[
                        'certificate'] = cert_root + request.remote_addr + ".crt"

            Utils.save_file(self.root + "/config/config.json",
                            self.config.get('data'))
        else:
            abort(400, message="invalid request")

        try:
            engine_certificate = Utils.read_file(
                self.config.get('data').get('security').get('ssl')
                ['certificate'])
        except Exception, ex:
            abort(500, message="failed to read engine certificate")

        open("/tmp/.flenginerestart", "w").write("restart")
        func = request.environ.get('werkzeug.server.shutdown')
        func()
        return {
            "message": "success",
コード例 #31
0
class Dataset:
	TYPE_POSITIVE = 0
	TYPE_NEGATIVE = 1
	TYPE_ACCURACY = 2
	TYPE_HEATMAP = 3
	
	LEFT_HAND = 0
	RIGHT_HAND = 1
	NO_HAND = 2
	
	DISTANCE_550 = 0
	DISTANCE_750 = 4
	DISTANCE_1000 = 1
	DISTANCE_1250 = 5
	DISTANCE_1500 = 2
	DISTANCE_1750 = 6
	DISTANCE_2000 = 3
	
	
	# Constructor of the Dataset class
	# 
	# @param	camera_height		Value of the camera height while gathering informations
	# @param	hand				Identifier of the hand (Ø|1|2)
	# @param	skeleton			Skeletal joints of the detected subject
	# @param	depth_map			Depth map of the captured scene
	# @param	image				RGB image of the captured scene
	# @param	type				Identifier of the type of data (0|1|2|3)
	# @param	distance			Identifier of the type of distance chosen (0|1|2|3|4|5|6) or the actual distance between the fingertip and the target
	# @param	target				Coordinates of the target
	# @return	None
	def __init__(self, camera_height=None, hand=None, skeleton=None, depth_map=None, image=None, type=None, distance=None, target=None):
		self.settings = Settings()
		self.utils = Utils()
		
		# Initialise each attributes with respective parameters; otherwise with a default value
		if camera_height is None:
			camera_height = 1500
		self.camera_height = camera_height
		
		if hand is None:
			hand = self.settings.LEFT_HAND
		self.hand = hand
		
		if skeleton is None:
			skeleton = {
				"head": [],
				"shoulder": {
					"left": [],
					"right": [],
					"center": []
				},
				"elbow": {
					"left": [],
					"right": []
				},
				"hand": {
					"left": [],
					"right": []
				}
			}
		self.skeleton = skeleton
		
		if depth_map is None:
			depth_map = []
		self.depth_map = np.array(depth_map)
		
		if image is None:
			image = ""
		self.image = image
		
		if type is None:
			type = Dataset.TYPE_POSITIVE
		self.type = type
		
		if distance is None:
			distance = Dataset.DISTANCE_550
		self.distance = distance
		
		if target is None:
			target = []
		self.target = target
	
	
	
	# Returns a JSON encoded string of the dataset object
	# 
	# @param	None
	# @return	string				JSON encoded string of the dataset object
	def to_JSON(self):
		# Convert the depth map to a serializable state
		self.depth_map = self.depth_map.tolist()
		
		# Encode the RGB image in a base64 string
		self.image = self.utils.getBase64(self.image)
		
		# Get rid of extra attributes to clean the output
		obj = deepcopy(self)
		del obj.settings
		del obj.utils
		
		return json.dumps(obj, default=lambda o: o.__dict__, separators=(',', ':'))
	
	
	
	# Save the dataset informations as a file
	# 
	# @param	None
	# @return	None
	def save(self):
		print "Saving dataset informations..."
		
		# Save the dataset to the right folder
		if self.type == Dataset.TYPE_POSITIVE:
			filename = self.settings.getPositiveFolder()
		elif self.type == Dataset.TYPE_NEGATIVE:
			filename = self.settings.getNegativeFolder()
		elif self.type == Dataset.TYPE_ACCURACY:
			filename = self.settings.getAccuracyFolder()
		else:
			raise ValueError("Invalid type of dataset to save", self.type)
		
		# Retrieve the number of files saved so far
		# Be careful that due to the sample file, the counter does not need to be incremented. Otherwise, the files would replace each others
		filename += str(self.utils.getFileNumberInFolder(filename)).zfill(3)+".json"
		self.utils.dumpJsonToFile(self.to_JSON(), filename)
	
	
	# Toggle the type identifier of the dataset
	# 
	# @param	value				Identifier of the new type of the dataset
	# @return	None
	def toggleType(self, value):
		self.type = value
		print "type toggled to {0}".format(value)
	
	
	# Toggle the distance identifier of the dataset
	# 
	# @param	value				Identifier of the new distance of the dataset
	# @return	None
	def toggleDistance(self, value):
		self.distance = value
		print "distance toggled to {0}".format(value)
	
	
	# Update the distance of the dataset
	# 
	# @param	value				Distance value
	# @return	None
	def setDistance(self, value):
		self.distance = value
		print "distance changed to {0}".format(value)
	
	
	# Toggle the hand identifier of the dataset
	# 
	# @param	value				Identifier of the new hand of the dataset
	# @return	None
	def toggleHand(self, value):
		self.hand = value
		print "hand toggled"
	
	
	# Returns the actual distance
	# 
	# @param	None
	# @return	numeric				Actual distance value (translated if identifier)
	def getWishedDistance(self):
		if self.distance == Dataset.DISTANCE_550:
			return 550
		elif self.distance == Dataset.DISTANCE_750:
			return 750
		elif self.distance == Dataset.DISTANCE_1000:
			return 1000
		elif self.distance == Dataset.DISTANCE_1250:
			return 1250
		elif self.distance == Dataset.DISTANCE_1500:
			return 1500
		elif self.distance == Dataset.DISTANCE_1750:
			return 1750
		elif self.distance == Dataset.DISTANCE_2000:
			return 2000
		else:
			return self.distance
コード例 #32
0
 def set_lineedit_testing_saved_models_directory(self):
     path = AppModel.get_instance().model['testing_saved_models_directory']
     self.lineedit_testing_saved_models_directory.setText(path)
     models_in_dir = Utils.list_files_with_extensions(path, ['.pth'])
     self.listWidget_testing_saved_models.addItems(models_in_dir)