-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GUI in separate thread (fix #189) #203
Open
regeciovad
wants to merge
11
commits into
rh-lab-q:master
Choose a base branch
from
regeciovad:issue189
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e8e9488
New class ThreadWrapper (#189)
regeciovad c1fc5f0
Gui - srpm build process is shown
regeciovad 06eae99
Gui - rpm build process is shown
regeciovad c309b49
Gui - cleanupPage in ImportPage
regeciovad 6367c2b
Gui - MandatoryPage's subtitle (fix #302)
regeciovad 32e2051
Gui- new text widget (fix #348)
regeciovad 6530d04
Gui - Loading cursor added (fix #361)
regeciovad 9533024
Gui - build info with SRPM, RPM and Copr (fix #189)
regeciovad d3d5666
Gui - copy rpm and sprm in wizard
regeciovad c8a5572
Gui - fix: undefined self.new_thread bug
regeciovad 5035702
Gui - fix: import url added
regeciovad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,9 +222,11 @@ def write_spec(self): | |
|
||
def build_srpm(self): | ||
""" Builds srpm into base directory. """ | ||
print('Building SRPM...') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
if not self.spec.Source or not self.archive_path.exists(): | ||
self.create_archive() | ||
self.write_spec() | ||
print('Spec file created.') | ||
self._package_builder.build_srpm( | ||
self.spec_path, self.archive_path, self.base_dir) | ||
|
||
|
@@ -274,6 +276,23 @@ def build_project(self): | |
self.compiled_dir, | ||
self.spec.build) | ||
|
||
def copr_create_and_build(self, name, chroots, desc, intro, url): | ||
print("Creating new project...") | ||
try: | ||
self.copr_create_project(name, chroots, desc, intro) | ||
except: | ||
print("Error in creating project! Please check your login.") | ||
return | ||
print("Creating new project - DONE") | ||
print("Build proccess started...") | ||
print("It takes a while, but it may be safely interrupted.") | ||
try: | ||
self.copr_build(name, url) | ||
except: | ||
print("Error in building project! Please check your url.") | ||
return | ||
print("Building new project - DONE") | ||
|
||
def copr_set_config(self, username, login, token): | ||
""" Logs into copr with username, login and token. | ||
This has to be called before copr_create_project and copr_build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from multiprocessing import Process, Queue | ||
from threading import Thread | ||
from io import StringIO | ||
from contextlib import redirect_stdout | ||
|
||
|
||
class _StringIO(StringIO): | ||
""" Overwriting of StringIO for real time output caching. """ | ||
|
||
def __init__(self, buff): | ||
super(_StringIO, self).__init__() | ||
self.buff = buff | ||
|
||
def write(self, s): | ||
super(_StringIO, self).write(s) | ||
if s and s != '\n': | ||
self.buff.put(s) | ||
|
||
|
||
class ThreadWrapper(): | ||
""" Unblocking way to connect functions with GUI for redirection | ||
it's output in real time. """ | ||
|
||
def __init__(self, widget, func, *args): | ||
""" Runs function in new process and add output | ||
to GUI widget from thread with queue. """ | ||
self._widget = widget | ||
self._queue = Queue() | ||
self._process = Process(target=self.wrapper, | ||
args=(self._queue, func, args, )) | ||
self._thread = Thread(target=self.writer) | ||
self._running = False | ||
|
||
def run(self): | ||
""" Starts the process and the thread. """ | ||
if not self._running: | ||
self._process.start() | ||
self._thread.start() | ||
self._running = True | ||
|
||
def kill(self): | ||
""" Stops the process and the thread (there are no official | ||
way to stop thread. This will unlocked thread and it will | ||
be stopped with GUI - without error). """ | ||
self._thread._tstate_lock = None | ||
self._thread._stop() | ||
self._thread.join() | ||
self._process.terminate() | ||
|
||
@staticmethod | ||
def wrapper(queue, func, args): | ||
""" Redirects stdout and call function. | ||
Output will be in queue.""" | ||
f = _StringIO(queue) | ||
with redirect_stdout(f): | ||
func(*args) | ||
f.close() | ||
|
||
def writer(self): | ||
""" Appends output from function to the GUI widget. """ | ||
while self._process.is_alive(): | ||
self._widget.appendPlainText(self._queue.get()) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use logging instead of prints, please