Пример #1
0
    def new_get_content(self, params, dir_only=None, file_only=None):
        directory = None
        br_history = None
        parser = DataParser()
        file_chooser = FileChooser()
        if (params["content_type"] == "image"
                or params["content_type"] == "audio"):
            if 'directory' in params:
                directory = parser.substr(stra=params['directory'],
                                          strb=getpass.getuser())
            if 'broadcast_history' in params:
                br_history = parser.substr(stra=params['broadcast_history'],
                                           strb=getpass.getuser())
            rec_fold = None
            if 'recursive_folders' in params:
                rec_fold = params['recursive_folders']
            br_hist_ftype = None
            if 'broadcast_history_ftype' in params:
                br_hist_ftype = params['broadcast_history_ftype']

            # file_loc, dir_only, file_name
            return file_chooser.get_file(params['selection_alg'], rec_fold,
                                         directory, br_history, br_hist_ftype)
        elif params["content_type"] == "text":
            data_file = parser.substr(stra=params['data_file'],
                                      strb=getpass.getuser())

            general_info = file_chooser.get_text(
                directory=dir_only,
                selection_alg=params['selection_alg'],
                data_file=data_file,
                data_format=params['data_format'],
                file_name=file_only)
            text = parser.format_caption(params['format_rules'], general_info)
            return text
Пример #2
0
 def test_select_random_unused_file(self):
     filech = FileChooser()
     directory, fpath, fname = filech.select_random_unused_file(
         False, self.mockinfo.mockdirwfiles, self.mockinfo.usedfiles)
     self.assertNotEqual(self.mockinfo.mockdirwfiles + "/infogeneral.json",
                         fpath)
     self.assertEqual(self.mockinfo.mockdirwfiles + "/file3.jpg", fpath)
Пример #3
0
 def create_item(self, content_item):
     parser = Parser()
     filechooser = FileChooser()
     textchooser = TextChooser()
     content_params = content_item.content_item[0]
     if content_params.content_type == "text":
         general_info = textchooser.get_text(
             content_params.selection_alg,
             content_params.data_file,
             content_params.data_format,
             None,
             None,
             application=content_item.application)
         if content_item.application == "poetry":
             content_item.item_text = parser.format_poem(
                 general_info[0], general_info[1])
         else:
             content_item.item_text = parser.format_caption(
                 content_params.format_rules, general_info)
         return content_item
     elif content_params.content_type == "image":
         image_path = filechooser.get_file(content_params.selection_alg,
                                           content_params.recursive_folders,
                                           content_params.directory,
                                           content_params.history_loc,
                                           content_params.history_ftype)
         content_item.item_image_path = image_path[0]
         if len(content_item.content_item) > 1:
             general_info = textchooser.get_text(
                 content_item.content_item[1].selection_alg,
                 content_item.content_item[1].data_file,
                 content_item.content_item[1].data_format, image_path[1],
                 image_path[2])
             content_item.item_text = parser.format_caption(
                 content_item.content_item[1].format_rules, general_info)
         return content_item
Пример #4
0
 def __init__(self):
     self.filechooser = FileChooser()
Пример #5
0
class ContentJson:
    def __init__(self):
        self.filechooser = FileChooser()

    def get_content(self, content_parameters, content_type):
        parser = DataParser()
        content = []
        info = None
        # print(content_parameters)
        for content_params in content_parameters:
            # print(content_params)
            if content_params["selection_alg"] == "description":
                description = self.filechooser.get_content_description(
                    content.pop(), content_params, info, content_type)
                content.append(description)
            else:
                # returns: file_dir, dir_only, file_only
                info = self.new_get_content(content_params)
                if isinstance(info, str):
                    item = parser.format_item_kv(
                        content_params["content_type"], info)
                else:
                    item = parser.format_item_kv(
                        content_params["content_type"], info[0])
                    if len(content_parameters) == 1:
                        tmp_list = []
                        tmp_list.append(item)
                        item = parser.format_item_kv(
                            content_params["content_type"], tmp_list)

                if content_type == 'list':
                    tmp_list = []
                    tmp_list.append(item)
                    item = parser.format_item_kv(
                        content_params["content_type"], tmp_list)

                content.append(item)
        return content

    def new_get_content(self, params, dir_only=None, file_only=None):
        directory = None
        br_history = None
        parser = DataParser()
        file_chooser = FileChooser()
        if (params["content_type"] == "image"
                or params["content_type"] == "audio"):
            if 'directory' in params:
                directory = parser.substr(stra=params['directory'],
                                          strb=getpass.getuser())
            if 'broadcast_history' in params:
                br_history = parser.substr(stra=params['broadcast_history'],
                                           strb=getpass.getuser())
            rec_fold = None
            if 'recursive_folders' in params:
                rec_fold = params['recursive_folders']
            br_hist_ftype = None
            if 'broadcast_history_ftype' in params:
                br_hist_ftype = params['broadcast_history_ftype']

            # file_loc, dir_only, file_name
            return file_chooser.get_file(params['selection_alg'], rec_fold,
                                         directory, br_history, br_hist_ftype)
        elif params["content_type"] == "text":
            data_file = parser.substr(stra=params['data_file'],
                                      strb=getpass.getuser())

            general_info = file_chooser.get_text(
                directory=dir_only,
                selection_alg=params['selection_alg'],
                data_file=data_file,
                data_format=params['data_format'],
                file_name=file_only)
            text = parser.format_caption(params['format_rules'], general_info)
            return text

    def get_content_description(self, content_item, content_params, info,
                                content_type):
        united_content = []
        united_content.append(content_item)

        # not supposed to be here
        dataparser = DataParser()

        item_text = dataparser.format_item_kv(
            "text", self.new_get_content(content_params, info[1], info[2]))
        united_content.append(item_text)

        item = dataparser.format_item_kv(content_type, united_content)
        return item
Пример #6
0
 def on_button_default_dest_clicked(self, widget):
     filechooser = FileChooser()
     filechooser.set_return_type(filechooser.RETURN_FILENAME)
     filechooser.set_exitnotify(self.filechosen_new_set_default_dest)
     filechooser.set_title(_("Select a default destination"))
     filechooser.show()
Пример #7
0
 def on_button_ssh_path_clicked(self, widget):
     host = self.builder.get_object('entry_ssh_host').get_text()
     user = self.builder.get_object('entry_ssh_user').get_text()
     if len(host) == 0 or len(user) == 0:
         return True
     filechooser = FileChooser()
     filechooser.set_return_type(filechooser.RETURN_URI)
     filechooser.set_exitnotify(self.filechosen_new_set_ssh_path)
     filechooser.set_title(_("Select a default remote location to backup to."))
     filechooser.show()
     filechooser.set_current_folder_uri("sftp://%s@%s/" %(user, host))
Пример #8
0
 def test_get_history(self):
     filechooser = FileChooser()
     result = filechooser.get_history(self.mockinfo.historyfile, "json")
     self.assertEqual(self.mockinfo.usedfiles, result)