Subversion Repositories basico

Rev

Rev 72 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 72 Rev 73
Line 25... Line 25...
25
from concurrent.futures import ThreadPoolExecutor as Executor
25
from concurrent.futures import ThreadPoolExecutor as Executor
26
26
27
from .service import Service
27
from .service import Service
28
28
29
SEP = os.path.sep
29
SEP = os.path.sep
30
PROPKEYS = ['tasks', 'id', 'title', 'type', 'componentkey', 'componenttxt',
-
 
31
            'category', 'version', 'priority', 'language', 'releaseon',
-
 
32
            'bookmark']
-
 
-
 
30
-
 
31
# PROPKEYS = CSV headers. SAP Note metadata
-
 
32
PROPKEYS = ['id', 'title', 'type', 'componentkey',
-
 
33
            'componenttxt', 'category', 'priority', 'releaseon',
-
 
34
            'language', 'version']
-
 
35
-
 
36
# Extend PROPKEYS with custom basico metadata
-
 
37
PROPKEYS.extend (['Tasks', 'Bookmark'])
33
38
34
class Callback(Service):
39
class Callback(Service):
35
    def initialize(self):
40
    def initialize(self):
36
        self.get_services()
41
        self.get_services()
37
42
Line 39... Line 44...
39
        self.gui = self.app.get_service('GUI')
44
        self.gui = self.app.get_service('GUI')
40
        self.uif = self.app.get_service("UIF")
45
        self.uif = self.app.get_service("UIF")
41
        self.sap = self.app.get_service('SAP')
46
        self.sap = self.app.get_service('SAP')
42
        self.tasks = self.app.get_service('Tasks')
47
        self.tasks = self.app.get_service('Tasks')
43
        self.alert = self.app.get_service('Notify')
48
        self.alert = self.app.get_service('Notify')
44
        self.stats = self.app.get_service('Stats')
-
 
-
 
49
        #~ self.stats = self.app.get_service('Stats')
45
        self.utils = self.app.get_service('Utils')
50
        self.utils = self.app.get_service('Utils')
46
51
47
    def execute_action(self, *args):
52
    def execute_action(self, *args):
48
        action = args[0]
53
        action = args[0]
49
        action_name = action.get_name()
54
        action_name = action.get_name()
Line 161... Line 166...
161
166
162
        if response == Gtk.ResponseType.OK:
167
        if response == Gtk.ResponseType.OK:
163
            export_path = dialog.get_filename()
168
            export_path = dialog.get_filename()
164
            writer = csv.writer(open(export_path, 'w'), delimiter=';', quoting=csv.QUOTE_ALL)
169
            writer = csv.writer(open(export_path, 'w'), delimiter=';', quoting=csv.QUOTE_ALL)
165
            csvrow = []
170
            csvrow = []
-
 
171
166
            for key in PROPKEYS:
172
            for key in PROPKEYS:
167
                csvrow.append(key)
-
 
-
 
173
                csvrow.append(key.capitalize())
168
            writer.writerow(csvrow)
174
            writer.writerow(csvrow)
-
 
175
169
            for tid in sapnotes:
176
            for tid in sapnotes:
170
                sid = "0"*(10 - len(tid)) + tid
177
                sid = "0"*(10 - len(tid)) + tid
171
                self.log.debug("Exporting SAP Note %s to CSV file" % sid)
178
                self.log.debug("Exporting SAP Note %s to CSV file" % sid)
172
                csvrow = []
179
                csvrow = []
173
                props = db.get_sapnote_metadata(sid)
180
                props = db.get_sapnote_metadata(sid)
-
 
181
174
                for prop in PROPKEYS:
182
                for prop in PROPKEYS:
175
                    if prop == 'tasks':
183
                    if prop == 'tasks':
176
                        tasks = ', '.join(props[prop])
184
                        tasks = ', '.join(props[prop])
177
                        csvrow.append(tasks)
185
                        csvrow.append(tasks)
178
                    else:
186
                    else:
Line 439... Line 447...
439
447
440
        self.log.debug("%d SAP Notes to be downloaded: %s" % (len(bag), ', '.join(list(bag))))
448
        self.log.debug("%d SAP Notes to be downloaded: %s" % (len(bag), ', '.join(list(bag))))
441
449
442
        resnotes = {}
450
        resnotes = {}
443
451
444
        driver.open()
-
 
-
 
452
        self.sap.start_fetching(len(bag))
445
        dlbag = {}
453
        dlbag = {}
-
 
454
-
 
455
        # FIXME: max_workers = 1 = Threads disabled
446
        with Executor(max_workers=1) as exe:
456
        with Executor(max_workers=1) as exe:
447
            jobs = []
457
            jobs = []
448
            for sapnote in bag:
458
            for sapnote in bag:
449
                job = exe.submit(self.sap.fetch, sapnote)
459
                job = exe.submit(self.sap.fetch, sapnote)
450
                jobs.append(job)
460
                jobs.append(job)
451
461
452
            for job in jobs:
462
            for job in jobs:
453
                rc, sapnote = job.result()
463
                rc, sapnote = job.result()
454
                self.log.debug("\tRC SAP Note %s: %s" % (sapnote, rc))
464
                self.log.debug("\tRC SAP Note %s: %s" % (sapnote, rc))
455
                resnotes[sapnote] = rc
465
                resnotes[sapnote] = rc
456
                time.sleep(1)
-
 
-
 
466
                time.sleep(0.1)
457
467
458
        driver.close()
468
        driver.close()
-
 
469
        self.sap.stop_fetching()
459
        db.save_notes()
470
        db.save_notes()
460
        db.build_stats()
471
        db.build_stats()
461
472
462
        textbuffer.set_text("")
473
        textbuffer.set_text("")
463
        self.log.info("Task completed.")
474
        self.log.info("Task completed.")
Line 715... Line 726...
715
        sapnoteview = self.gui.get_widget('sapnoteview')
726
        sapnoteview = self.gui.get_widget('sapnoteview')
716
727
717
        tasks_selected = len(tasks.get_selected()) > 0
728
        tasks_selected = len(tasks.get_selected()) > 0
718
        notes_selected = len(sapnoteview.get_selected_notes()) > 0
729
        notes_selected = len(sapnoteview.get_selected_notes()) > 0
719
        if  tasks_selected and notes_selected:
730
        if  tasks_selected and notes_selected:
720
            button.set_no_show_all(False)
-
 
-
 
731
            #~ button.set_no_show_all(False)
721
            #~ button.show_all()
732
            #~ button.show_all()
722
            button.set_sensitive(True)
733
            button.set_sensitive(True)
723
            self.log.debug("Task link button enabled")
734
            self.log.debug("Task link button enabled")
724
        else:
735
        else:
725
            #~ button.hide()
736
            #~ button.hide()