Beispiel #1
0
 def _file_selector_add(self):
     self._fs_filecounter = 0
     self._fs = FileSelector(self)
     self._fs.filter = self._fs_filter
     self._fs.multi = False
     self.action_disabled_set("add_new_file", "Select", True)
     self._fs.callback_add("file.selected", self._fs_file_selected_cb)
     self._fs.callback_add("file.unselected", self._fs_file_unselected_cb)
     self._fs.show()
Beispiel #2
0
 def __init__(self, master=None, root_path=None):
     super().__init__(master)
     self.master = master
     self.root_path = root_path
     self.fs = FileSelector()
     self.outfile = tk.StringVar()
     #
     # calling initialise functions
     #
     self.master.resizable(width=False, height=False)
     self._createWidgets()
     self._bindEvents()
     self._setLayout()
Beispiel #3
0
    def __init__(self, open_cb, *args, **kargs):
        elementary.Window.__init__(self, "openfile",
                                   elementary.ELM_WIN_BASIC)
        self.title_set("Open file")
        self.autodel_set(True)

        self._open_cb = (open_cb, args, kargs)

        bg = elementary.Background(self)
        self.resize_object_add(bg)
        bg.size_hint_weight_set(evas.EVAS_HINT_EXPAND,
                                evas.EVAS_HINT_EXPAND)
        bg.show()

        self._fs = FileSelector(self)
        self._fs.filter = self._filter
        self._fs.action_add("Cancel", self._cancel)
        self._fs.action_add("Ok", self._open)
        self._fs.action_disabled_set("Ok", True)
        self._fs.callback_add("file.clicked", self._file_clicked)
        self._fs.callback_add("file.selected", self._file_selected)
        self._fs.callback_add("file.selection_clear", self._file_unselected)
        self.resize_object_add(self._fs)
        self._fs.show()

        self.resize(600, 480)
Beispiel #4
0
 def _file_selector_add(self):
     self._fs_filecounter = 0
     self._fs = FileSelector(self)
     self._fs.filter = self._fs_filter
     self._fs.multi = False
     self.action_disabled_set("add_new_file", "Select", True)
     self._fs.callback_add("file.selected", self._fs_file_selected_cb)
     self._fs.callback_add("file.unselected", self._fs_file_unselected_cb)
     self._fs.show()
Beispiel #5
0
    def __init__(self, open_cb, *args, **kargs):
        elementary.Window.__init__(self, "openfile", elementary.ELM_WIN_BASIC)
        self.title_set("Open file")
        self.autodel_set(True)

        self._open_cb = (open_cb, args, kargs)

        bg = elementary.Background(self)
        self.resize_object_add(bg)
        bg.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
        bg.show()

        self._fs = FileSelector(self)
        self._fs.filter = self._filter
        self._fs.action_add("Cancel", self._cancel)
        self._fs.action_add("Ok", self._open)
        self._fs.action_disabled_set("Ok", True)
        self._fs.callback_add("file.clicked", self._file_clicked)
        self._fs.callback_add("file.selected", self._file_selected)
        self._fs.callback_add("file.selection_clear", self._file_unselected)
        self.resize_object_add(self._fs)
        self._fs.show()

        self.resize(600, 480)
Beispiel #6
0
class Application(tk.Frame):
    def __init__(self, master=None, root_path=None):
        super().__init__(master)
        self.master = master
        self.root_path = root_path
        self.fs = FileSelector()
        self.outfile = tk.StringVar()
        #
        # calling initialise functions
        #
        self.master.resizable(width=False, height=False)
        self._createWidgets()
        self._bindEvents()
        self._setLayout()

    def _createWidgets(self):
        self.grid(row=7, column=5, sticky="nsew")
        #self.master.minsize(325, 245)
        self.label2 = tk.Label(self, text="File Name")
        self.entry = tk.Entry(self, textvariable=self.outfile) 
        self.browse = tk.Button(self, text="Browse")
        self.process = tk.Button(self, text="Process")
        self.lbox = tk.Listbox(self, selectmode=tk.SINGLE,
                width=58, height=15)
        self.btn_delete = tk.Button(self, text="Delete")
        self.labelB = tk.Label(self, text="")
        self.moveup = tk.Button(self, text=" Up ")
        self.movedown = tk.Button(self, text="Down")

    def _bindEvents(self):
        self.browse.bind('<ButtonRelease-1>', self._actionBrowse)
        self.process.bind('<ButtonRelease-1>', self._process)
        self.moveup.bind('<ButtonRelease-1>', self._moveup)
        self.movedown.bind('<ButtonRelease-1>', self._movedown)
        self.btn_delete.bind('<ButtonRelease-1>', self._actionDelete)

    def _setLayout(self):
        self.label2.grid(
                row=0, column=0, sticky='ew', 
                padx=2, pady=2
                )
        self.entry.grid(
                row=0, column=1, sticky="ew",
                columnspan=3, 
                padx=2, pady=2
                )
        self.browse.grid(
                row=1, column=4, sticky="ew"
                )
        self.process.grid(
                row=2, column=4, sticky="ew"
                )
        self.lbox.grid(
                row=1, column=0, sticky="nsew",
                rowspan=5, columnspan=4,
                padx=2, pady=0
                )
        self.btn_delete.grid(
                row=6, column=0, sticky="ew"
                )
        self.labelB.grid(
                row=6, column=1, sticky="ew"
                )
        self.moveup.grid(
                row=6, column=2, sticky="ew",
                padx=0, pady=2
                )
        self.movedown.grid(
                row=6, column=3, sticky="ew",
                padx=2, pady=2
                )

    def _actionBrowse(self, event=None):
        if self.fs.selectFolder2(spath = self.root_path):
            #
            # folder parsing is success
            # need to populate list-box
            #
            self.fillListBox(self.fs.getList().keys())

    def fillListBox(self, itemlist):
        self.lbox.delete(0, 'end')
        for item in itemlist:
            self.lbox.insert('end', item)

    def insertToListBox(self, item, pos='end'):
        self.lbox.insert(pos, item)

    def _moveup(self, event=None):
        index = self.lbox.curselection()
        if not index:
            return
        #
        # list of selected items returned
        # in case of tk.EXTENDED
        #
        for pos in index:
            if pos == 0:
                continue
            text = self.lbox.get(pos)
            self.lbox.delete(pos)
            self.lbox.insert(pos - 1, text)
            #
            # to keep the selection
            #
            self.lbox.selection_set(pos - 1)

    def _movedown(self, event=None):
        index = self.lbox.curselection()
        if not index:
            return
        for pos in index:
            if pos == self.lbox.size() - 1:
                # 
                # checking if current selection is last item
                #
                continue
            text = self.lbox.get(pos)
            self.lbox.delete(pos)
            self.lbox.insert(pos + 1, text)
            self.lbox.selection_set(pos + 1)

    def _actionDelete(self, event=None):
        index = self.lbox.curselection()
        if not index:
            messagebox.showerror(
                    'Error',
                    'Kindly select item to delete'
                    )
            return
        text = self.lbox.get(index[0])
        self.lbox.delete(index[0])
        self.fs.removeKey(text)

    def _process(self, event=None):
        try:
            self._workerProcess()
        except:
            #
            # to catch any missed exception
            #
            print(sys.exc_info()[0])
            messagebox.showerror(
                    'Failed',
                    'Unable to process due to exception\n' \
                    'try run in terminal'
                    )

    def _workerProcess(self):
        if not self._validate():
            return
        cmd = [
                'gs', 
                '-dBATCH', '-dNOPAUSE', 
                '-sDEVICE=pdfwrite',
                '-dPDFSETTINGS=/prepress'
                #'-sOutputFile=##OUTNAME##'
                ]
        #
        # check out-filename
        # and append to final 'gs' command
        #
        outfile = '-sOutputFile='+ self.root_path +'/'+ self.outfile.get()
        if not outfile.endswith('.pdf'):
            outfile = outfile + '.pdf'
        cmd.append(outfile)
        #
        # append PDF files to final commmand
        #
        var_dictionary = self.fs.getList()
        for item in self.lbox.get(0, 'end'):
            cmd.append(var_dictionary[item])
        #
        # execute final command
        #
        print(cmd)
        proc = subprocess.Popen(cmd,
                stdout = subprocess.PIPE,
                stderr = subprocess.PIPE)
        stdout, stderr = proc.communicate()
        if stderr:
            messagebox.showerror(
                    'Failed',
                    stderr
                    )
        else:
            messagebox.showinfo(
                    'Completed',
                    'Operation Success'
                    )

    def _validate(self):
        if not self.fs.getList():
            messagebox.showerror(
                    'Missing input',
                    'Kindly select input pdf file(s)'
                    )
            return False
        if not self.outfile.get():
            messagebox.showerror(
                    'Missing entry',
                    'Kindly provide Filename'
                    )
            return False
        return True
Beispiel #7
0
class OpenFile(elementary.Window):
    _notification = None

    def __init__(self, open_cb, *args, **kargs):
        elementary.Window.__init__(self, "openfile", elementary.ELM_WIN_BASIC)
        self.title_set("Open file")
        self.autodel_set(True)

        self._open_cb = (open_cb, args, kargs)

        bg = elementary.Background(self)
        self.resize_object_add(bg)
        bg.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
        bg.show()

        self._fs = FileSelector(self)
        self._fs.filter = self._filter
        self._fs.action_add("Cancel", self._cancel)
        self._fs.action_add("Ok", self._open)
        self._fs.action_disabled_set("Ok", True)
        self._fs.callback_add("file.clicked", self._file_clicked)
        self._fs.callback_add("file.selected", self._file_selected)
        self._fs.callback_add("file.selection_clear", self._file_unselected)
        self.resize_object_add(self._fs)
        self._fs.show()

        self.resize(600, 480)

    def show(self):
        self.activate()
        elementary.Window.show(self)

    def _file_clicked(self, obj, data):
        self._open(None)

    def _file_selected(self, obj, data):
        self._fs.action_disabled_set("Ok", False)

    def _file_unselected(self, obj, data):
        self._fs.action_disabled_set("Ok", True)

    def _filter(self, file):
        return file.endswith(".edc") or file.endswith(".edj")

    def _path_set(self, value):
        self._fs.path = value

    path = property(fset=_path_set)

    def _open_ok(self, sf, **kargs):
        self.hide()
        open_cb, args, kargs = self._open_cb
        open_cb(sf, *args, **kargs)
        self.delete()

    def _open(self, bt, mode=None):
        swapfile.open(self._fs.file, self._open_ok, self._notify_err, mode)

    def _open_forced(self, bt, data):
        self._open(bt, swapfile.REPLACE)

    def _open_recovery(self, bt, data):
        self._open(bt, swapfile.RESTORE)

    def list_files_on_diretory(self):
        path = os.getenv("PWD")
        list = os.listdir(path)
        list.sort(key=str.lower)
        files = []
        for file in list:
            if not file.startswith("."):
                full = os.path.join(path, file)
                if os.path.isfile(full):
                    if file.endswith(".edj"):
                        files.append(file)
        return files

    def _cancel(self, bt):
        self.delete()

    def _notify_del(self):
        if self._notification:
            self._notification.hide()
            self._notification.delete()
            self._notification = None

    def _notify(self, message):
        self._notify_del()
        self._notification = elementary.Notify(self)
        self._notification.timeout_set(2)
        self._notification.orient_set(
            elementary.ELM_NOTIFY_ORIENT_BOTTOM_RIGHT)

        bx = elementary.Box(self)
        bx.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
        bx.horizontal_set(True)
        self._notification.content_set(bx)
        bx.show()

        lb = elementary.Label(self)
        lb.text_set(message)
        bx.pack_end(lb)
        lb.show()

        self._notification.show()

    def _notify_err(self, err, **kargs):
        if self._notification:
            self._notification.hide()
            self._notification.delete()
            self._notification = None

        self._notification = ErrorNotify(self)

        if isinstance(err, IOError) and err.errno == errno.EEXIST:
            self._notification.title = "Swap file already exists"
            lb = elementary.Label(self._notification)
            lb.text_set("Another program may be editing the same file<br>" +
                        "or a previous edition session for this file crashed.")
            self._notification.pack_end(lb)
            lb.show()
            self._notification.action_add("Ignore Swap", self._open_forced)
            self._notification.action_add("Recover", self._open_recovery)
            self._notification.action_add("Abort", self._notify_abort)
        elif isinstance(err, swapfile.CompileError):
            self._notification.title = "Compiler Error"
            lb = elementary.Label(self._notification)
            lb.text_set(str(err.message).replace('\n', '<br>'))
            self._notification.pack_end(lb)
            lb.show()
            self._notification.action_add("Ok", self._notify_abort)
        else:
            self._notification.title = str(err).replace(':', '<br>')
            self._notification.action_add("Ok", self._notify_abort)

        self._notification.show()

    def _notify_abort(self, bt, data):
        self._notify_del()
Beispiel #8
0
class FileSelectionWizard(Wizard):
    def __init__(self, parent, selected_cb, file_add_cb):
        Wizard.__init__(self, parent)

        self._selected_cb = selected_cb
        self._file_add_cb = file_add_cb

        self._selection = ""

        self._file_list_page_created = False
        self._add_new_file_page_created = False
        self._file_preview_page_created = False

        self._file_list_add()

        if self._files == []:
            self._create_add_new_file_page()
        else:
            self._create_file_list_page()

    def _create_file_list_page(self):
    #file list - page create and populate
        self._file_list_page_created = True
        self._add_file_list_header()

        self.content_add("file_list", self._file_list)
        self.action_add("file_list", "Cancel", self.close, key="Escape")
        self.action_add(
            "file_list", "Add New", self._goto_add_new_file, key="n")

    def _create_add_new_file_page(self):
    #file selector - page create and populate
        self._add_new_file_page_created = True
        self._add_add_new_file_header()

        self.action_add("add_new_file", "Go To List", self._back, key="Escape")
        self.action_add("add_new_file", "Select", self._new_file_added,
                        key="Return")

        self._file_selector_add()
        self.content_add("add_new_file", self._fs)

    def _create_file_preview_page(self):
    #file preview - page create and populate
        self._file_preview_page_created = True
        self._add_file_preview_header()

        self.action_add("file_preview", "Go To List", self._back, key="Escape")
        self.action_add("file_preview", "Delete", self._delete_file,
                        key="Delete")
        self.action_add("file_preview", "Use", self._file_selected,
                        key="Return")

        self._add_files_to_preview()

    def goto(self, page, alt_bg_style=None):
        Wizard.goto(self, page)

    def _goto_add_new_file(self):
        if not self._add_new_file_page_created:
            self._create_add_new_file_page()
        self.goto("add_new_file", alt_bg_style=True)

    def _goto_preview(self, obj=None, part=None, item_data=None):
        self._selection = item_data

        if not self._file_preview_page_created:
            self._create_file_preview_page()
        else:
            self._get_preview_file(self._selection)

        self.goto("file_preview", alt_bg_style=False)
        self._get_title_text()

    def _goto_files_list(self):
        self._update()
        self.goto("file_list", alt_bg_style=False)

    def _file_list_add(self):
        self._files = []
        self._file_list = elementary.Genlist(self)
        self._file_list.size_hint_align_set(
            evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL)
        self._file_list.size_hint_weight_set(
            evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
        self._update()
        self._file_list.show()

    def _file_selector_add(self):
        self._fs_filecounter = 0
        self._fs = FileSelector(self)
        self._fs.filter = self._fs_filter
        self._fs.multi = False
        self.action_disabled_set("add_new_file", "Select", True)
        self._fs.callback_add("file.selected", self._fs_file_selected_cb)
        self._fs.callback_add("file.unselected", self._fs_file_unselected_cb)
        self._fs.show()

    def _preview_scroller_add(self):
        self._preview_scroller = elementary.Scroller(self)
        self._preview_scroller.size_hint_align_set(
            evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL)
        self._preview_scroller.size_hint_weight_set(
            evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
        self._preview_scroller.policy_set(elementary.ELM_SCROLLER_POLICY_AUTO,
                                          elementary.ELM_SCROLLER_POLICY_AUTO)
        self._preview_scroller.bounce_set(False, False)
        self._preview_scroller.content_set(self._preview_file)
        self._preview_scroller.show()
        self.content_add("file_preview", self._preview_scroller)

    def _new_file_added(self):
        for i in self._fs.files:
            self._file_add_cb(i)
        new_file = os.path.basename(i)
        self._goto_preview(item_data=new_file)

    def _fs_file_selected_cb(self, obj, data):
        if data:
            self._fs_filecounter += 1
        self.action_disabled_set("add_new_file", "Select", False)

    def _fs_file_unselected_cb(self, obj, data):
        if data:
            self._fs_filecounter -= 1
        if self._fs_filecounter == 0:
            self.action_disabled_set("add_new_file", "Select", True)

    def _back(self):
        if not self._file_list_page_created:
            self._create_file_list_page()
        self._goto_files_list()

    def _back_file_preview(self):
        self._preview_file.hide()
        self._back()

    def _delete_file(self):
        print "FIXME: File deletion to be added soon"
        self.notify("File deletion to be added soon")
        self.goto("file_list")

    def _file_selected(self):
        self._selected_cb(self._selection)
        self.close()

    def _gl_label_get(self, *kargs):
        return kargs[-1]
Beispiel #9
0
class FileSelectionWizard(Wizard):
    def __init__(self, parent, selected_cb, file_add_cb):
        Wizard.__init__(self, parent)

        self._selected_cb = selected_cb
        self._file_add_cb = file_add_cb

        self._selection = ""

        self._file_list_page_created = False
        self._add_new_file_page_created = False
        self._file_preview_page_created = False

        self._file_list_add()

        if self._files == []:
            self._create_add_new_file_page()
        else:
            self._create_file_list_page()

    def _create_file_list_page(self):
        #file list - page create and populate
        self._file_list_page_created = True
        self._add_file_list_header()

        self.content_add("file_list", self._file_list)
        self.action_add("file_list", "Cancel", self.close, key="Escape")
        self.action_add("file_list",
                        "Add New",
                        self._goto_add_new_file,
                        key="n")

    def _create_add_new_file_page(self):
        #file selector - page create and populate
        self._add_new_file_page_created = True
        self._add_add_new_file_header()

        self.action_add("add_new_file", "Go To List", self._back, key="Escape")
        self.action_add("add_new_file",
                        "Select",
                        self._new_file_added,
                        key="Return")

        self._file_selector_add()
        self.content_add("add_new_file", self._fs)

    def _create_file_preview_page(self):
        #file preview - page create and populate
        self._file_preview_page_created = True
        self._add_file_preview_header()

        self.action_add("file_preview", "Go To List", self._back, key="Escape")
        self.action_add("file_preview",
                        "Delete",
                        self._delete_file,
                        key="Delete")
        self.action_add("file_preview",
                        "Use",
                        self._file_selected,
                        key="Return")

        self._add_files_to_preview()

    def goto(self, page, alt_bg_style=None):
        Wizard.goto(self, page)

    def _goto_add_new_file(self):
        if not self._add_new_file_page_created:
            self._create_add_new_file_page()
        self.goto("add_new_file", alt_bg_style=True)

    def _goto_preview(self, obj=None, part=None, item_data=None):
        self._selection = item_data

        if not self._file_preview_page_created:
            self._create_file_preview_page()
        else:
            self._get_preview_file(self._selection)

        self.goto("file_preview", alt_bg_style=False)
        self._get_title_text()

    def _goto_files_list(self):
        self._update()
        self.goto("file_list", alt_bg_style=False)

    def _file_list_add(self):
        self._files = []
        self._file_list = elementary.Genlist(self)
        self._file_list.size_hint_align_set(evas.EVAS_HINT_FILL,
                                            evas.EVAS_HINT_FILL)
        self._file_list.size_hint_weight_set(evas.EVAS_HINT_EXPAND,
                                             evas.EVAS_HINT_EXPAND)
        self._update()
        self._file_list.show()

    def _file_selector_add(self):
        self._fs_filecounter = 0
        self._fs = FileSelector(self)
        self._fs.filter = self._fs_filter
        self._fs.multi = False
        self.action_disabled_set("add_new_file", "Select", True)
        self._fs.callback_add("file.selected", self._fs_file_selected_cb)
        self._fs.callback_add("file.unselected", self._fs_file_unselected_cb)
        self._fs.show()

    def _preview_scroller_add(self):
        self._preview_scroller = elementary.Scroller(self)
        self._preview_scroller.size_hint_align_set(evas.EVAS_HINT_FILL,
                                                   evas.EVAS_HINT_FILL)
        self._preview_scroller.size_hint_weight_set(evas.EVAS_HINT_EXPAND,
                                                    evas.EVAS_HINT_EXPAND)
        self._preview_scroller.policy_set(elementary.ELM_SCROLLER_POLICY_AUTO,
                                          elementary.ELM_SCROLLER_POLICY_AUTO)
        self._preview_scroller.bounce_set(False, False)
        self._preview_scroller.content_set(self._preview_file)
        self._preview_scroller.show()
        self.content_add("file_preview", self._preview_scroller)

    def _new_file_added(self):
        for i in self._fs.files:
            self._file_add_cb(i)
        new_file = os.path.basename(i)
        self._goto_preview(item_data=new_file)

    def _fs_file_selected_cb(self, obj, data):
        if data:
            self._fs_filecounter += 1
        self.action_disabled_set("add_new_file", "Select", False)

    def _fs_file_unselected_cb(self, obj, data):
        if data:
            self._fs_filecounter -= 1
        if self._fs_filecounter == 0:
            self.action_disabled_set("add_new_file", "Select", True)

    def _back(self):
        if not self._file_list_page_created:
            self._create_file_list_page()
        self._goto_files_list()

    def _back_file_preview(self):
        self._preview_file.hide()
        self._back()

    def _delete_file(self):
        print "FIXME: File deletion to be added soon"
        self.notify("File deletion to be added soon")
        self.goto("file_list")

    def _file_selected(self):
        self._selected_cb(self._selection)
        self.close()

    def _gl_text_get(self, *kargs):
        return kargs[-1]
Beispiel #10
0
    def run(self):
        host_config = {}

        host_config['id'] = self.askHostId()

        host_config['address'] = self.askHostAddress()

        host_config['os'] = self.askOS()

        host_config['distro'] = self.askDistro(host_config['os'])

        host_config['dev'] = self.askDevEnv(host_config['distro'])

        host_config['user'] = self.askUsername()

        print

        usekey = self.askUseKeySecurity()

        while (usekey):
            fileSelector = FileSelector(constants.KEY_FILES_DIR,
                                        (".pem", ".ppk"),
                                        constants.KEY_FILE_TEXT)
            keyFile = fileSelector.select()
            if (not keyFile):
                print constants.NO_KEY_AVAILABLE
                print
                usekey = not self.askFallbackToPass()
            else:
                host_config['key-file'] = keyFile
                host_config['security'] = 'key'
                break

        if (not usekey):
            host_config['security'] = 'pass'
            host_config['pass'] = self.askPass()

        usePreTask = self.askUsePreparationTaskFile()
        if (usePreTask):
            fileSelector = FileSelector(constants.PREPARED_TASKS_DIR,
                                        constants.PLAYBOOK_FILE_EXTENSION,
                                        constants.PREPARATION_TASK_FILE_TEXT)
            taskFile = fileSelector.select()
            if (taskFile):
                host_config[
                    'pre-tasks'] = constants.PREPARED_TASKS_DIR + "/" + taskFile
            else:
                print
                print "[Error] No prepared tasks available. Place prepared playbooks in '" + constants.PREPARED_TASKS_DIR + "' directory and run again."
                print

        print

        configFile = constants.CONFIGS_DIR + '/' + host_config[
            'os'] + constants.CONFIG_FILE_EXTENSION

        packageHandler = PackageHandler(configFile)

        host_config['packages'] = packageHandler.selectPackages(host_config)
        host_config[
            'additional_packages'] = packageHandler.selectAdditionalPackages()

        print

        usePostTask = self.askUsePostInstallTaskFile()
        if (usePostTask):
            fileSelector = FileSelector(
                constants.PREPARED_TASKS_DIR, (".yml", ".yaml"),
                constants.POST_INSTALLATION_TASK_FILE_TEXT)
            taskFile = fileSelector.select()
            if (taskFile):
                host_config[
                    'post-tasks'] = constants.PREPARED_TASKS_DIR + "/" + taskFile
            else:
                print
                print "[Error] No prepared tasks available. Place prepared playbooks in '" + constants.PREPARED_TASKS_DIR + "' directory and run again."
                print

        inventory_creator = InventoryCreator()
        inventory_creator.create(host_config, constants.INVENTORIES_DIR)

        playbook_creator = PlaybookCreator()
        playbook_creator.create(host_config, constants.PLAYBOOKS_DIR)

        print
        print "Successfully created entry for " + host_config['id']
        print
Beispiel #11
0
class OpenFile(elementary.Window):
    _notification = None

    def __init__(self, open_cb, *args, **kargs):
        elementary.Window.__init__(self, "openfile",
                                   elementary.ELM_WIN_BASIC)
        self.title_set("Open file")
        self.autodel_set(True)

        self._open_cb = (open_cb, args, kargs)

        bg = elementary.Background(self)
        self.resize_object_add(bg)
        bg.size_hint_weight_set(evas.EVAS_HINT_EXPAND,
                                evas.EVAS_HINT_EXPAND)
        bg.show()

        self._fs = FileSelector(self)
        self._fs.filter = self._filter
        self._fs.action_add("Cancel", self._cancel)
        self._fs.action_add("Ok", self._open)
        self._fs.action_disabled_set("Ok", True)
        self._fs.callback_add("file.clicked", self._file_clicked)
        self._fs.callback_add("file.selected", self._file_selected)
        self._fs.callback_add("file.selection_clear", self._file_unselected)
        self.resize_object_add(self._fs)
        self._fs.show()

        self.resize(600, 480)

    def show(self):
        self.activate()
        elementary.Window.show(self)

    def _file_clicked(self, obj, data):
        self._open(None)

    def _file_selected(self, obj, data):
        self._fs.action_disabled_set("Ok", False)

    def _file_unselected(self, obj, data):
        self._fs.action_disabled_set("Ok", True)

    def _filter(self, file):
        return file.endswith(".edc") or file.endswith(".edj")

    def _path_set(self, value):
        self._fs.path = value

    path = property(fset=_path_set)

    def _open_ok(self, sf, **kargs):
        self.hide()
        open_cb, args, kargs = self._open_cb
        open_cb(sf, *args, **kargs)
        self.delete()

    def _open(self, bt, mode=None):
        swapfile.open(self._fs.file, self._open_ok, self._notify_err, mode)

    def _open_forced(self, bt, data):
        self._open(bt, swapfile.REPLACE)

    def _open_recovery(self, bt, data):
        self._open(bt, swapfile.RESTORE)

    def list_files_on_diretory(self):
        path = os.getenv("PWD")
        list = os.listdir(path)
        list.sort(key=str.lower)
        files = []
        for file in list:
            if not file.startswith("."):
                full = os.path.join(path, file)
                if os.path.isfile(full):
                    if file.endswith(".edj"):
                        files.append(file)
        return files

    def _cancel(self, bt):
        self.delete()

    def _notify_del(self):
        if self._notification:
            self._notification.hide()
            self._notification.delete()
            self._notification = None

    def _notify(self, message):
        self._notify_del()
        self._notification = elementary.Notify(self)
        self._notification.timeout_set(2)
        self._notification.orient_set(
            elementary.ELM_NOTIFY_ORIENT_BOTTOM_RIGHT)

        bx = elementary.Box(self)
        bx.size_hint_weight_set(evas.EVAS_HINT_EXPAND,
                                evas.EVAS_HINT_EXPAND)
        bx.horizontal_set(True)
        self._notification.content_set(bx)
        bx.show()

        lb = elementary.Label(self)
        lb.text_set(message)
        bx.pack_end(lb)
        lb.show()

        self._notification.show()

    def _notify_err(self, err, **kargs):
        if self._notification:
            self._notification.hide()
            self._notification.delete()
            self._notification = None

        self._notification = ErrorNotify(self)

        if isinstance(err, IOError) and err.errno == errno.EEXIST:
            self._notification.title = "Swap file already exists"
            lb = elementary.Label(self._notification)
            lb.text_set(
                "Another program may be editing the same file<br>" +
                "or a previous edition session for this file crashed.")
            self._notification.pack_end(lb)
            lb.show()
            self._notification.action_add("Ignore Swap", self._open_forced)
            self._notification.action_add("Recover", self._open_recovery)
            self._notification.action_add("Abort", self._notify_abort)
        elif isinstance(err, swapfile.CompileError):
            self._notification.title = "Compiler Error"
            lb = elementary.Label(self._notification)
            lb.text_set(str(err.message).replace('\n', '<br>'))
            self._notification.pack_end(lb)
            lb.show()
            self._notification.action_add("Ok", self._notify_abort)
        else:
            self._notification.title = str(err).replace(':', '<br>')
            self._notification.action_add("Ok", self._notify_abort)

        self._notification.show()

    def _notify_abort(self, bt, data):
        self._notify_del()