-
Notifications
You must be signed in to change notification settings - Fork 253
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
Detect Python 2 activities before they launch #992
Changes from all commits
fde05d6
101f100
3c585a4
d298bb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import os | ||
import hashlib | ||
from gettext import gettext as _ | ||
import re | ||
|
||
from gi.repository import Gio | ||
from gi.repository import Gtk | ||
|
@@ -258,20 +259,58 @@ def ready_callback(metadata, source, destination): | |
model.copy(metadata, '/', ready_callback=ready_callback) | ||
|
||
|
||
def is_python2_activity(bundle): | ||
# Path to the main activity file | ||
activity_file_path = os.path.join(bundle.get_path(), 'activity.py') | ||
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. Many activities do not have an activity.py file. |
||
|
||
if not os.path.exists(activity_file_path): | ||
return False # No activity file found | ||
|
||
with open(activity_file_path, 'r') as f: | ||
content = f.read() | ||
|
||
# Check for Python 2 specific syntax patterns | ||
python2_patterns = [ | ||
r'print\s+[^()]*$', # Print statement without parentheses | ||
r'except\s+.*,\s*', # Old exception syntax | ||
r'raw_input\s*\(', # raw_input function (Python 2) | ||
r'long\s+', # long type (Python 2) | ||
r'iteritems\s*\(', # iteritems method (Python 2) | ||
r'xrange\s*\(', # xrange function (Python 2) | ||
r'__future__\s+import\s+print_function', # Future import for print function | ||
r'from\s+ConfigParser', # ConfigParser module (Python 2) | ||
r'from\s+urlparse', # urlparse module (Python 2) | ||
r'from\s+StringIO', # StringIO module (Python 2) | ||
r'from\s+collections\s+import\s+OrderedDict', # OrderedDict import (Python 2) | ||
] | ||
|
||
# Check for any Python 2 patterns in the content | ||
for pattern in python2_patterns: | ||
if re.search(pattern, content): | ||
return True # Detected Python 2 syntax | ||
|
||
return False # Default to Python 3 | ||
|
||
|
||
def launch(bundle, activity_id=None, object_id=None, uri=None, color=None, | ||
invited=False, alert_window=None): | ||
|
||
bundle_id = bundle.get_bundle_id() | ||
|
||
# Check if the activity is a Python 2 activity | ||
if is_python2_activity(bundle): | ||
logging.warning('Attempted to launch a Python 2 activity: %s', bundle_id) | ||
# Emit a failure notification | ||
shell.get_model().notify_launch_failed(activity_id) | ||
return | ||
|
||
if activity_id is None or not activity_id: | ||
activity_id = activityfactory.create_activity_id() | ||
|
||
logging.debug('launch bundle_id=%s activity_id=%s object_id=%s uri=%s', | ||
bundle.get_bundle_id(), activity_id, object_id, uri) | ||
|
||
if isinstance(bundle, ContentBundle): | ||
# Content bundles are a special case: we treat them as launching | ||
# Browse with a specific URI. | ||
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. Why remove this comment? |
||
uri = bundle.get_start_uri() | ||
activities = get_activities_for_mime('text/html') | ||
if len(activities) == 0: | ||
|
@@ -297,7 +336,6 @@ def launch(bundle, activity_id=None, object_id=None, uri=None, color=None, | |
|
||
if not shell_model.can_launch_activity_instance(bundle): | ||
if alert_window is None: | ||
from jarabe.desktop import homewindow | ||
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. Why remove this import? |
||
alert_window = homewindow.get_instance() | ||
if alert_window is not None: | ||
alerts.show_multiple_instance_alert( | ||
|
@@ -429,4 +467,4 @@ def get_mount_color(mount): | |
color = XoColor('%s,%s' % | ||
(colors[index][0], | ||
colors[index][1])) | ||
return color | ||
return color | ||
amannaik247 marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
Change removed newline at end of file. Did you review your change before commit?