Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tractor
carburetor
Commits
ad2c1987
Commit
ad2c1987
authored
Mar 25, 2021
by
Danial Behzadi
Browse files
cleanup source code
parent
b40a3789
Changes
9
Hide whitespace changes
Inline
Side-by-side
carburetor/about.ui
View file @
ad2c1987
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2
Copyright (C) 2019 - 202
0
Copyright (C) 2019 - 202
1
This file is part of Carburetor.
...
...
@@ -26,7 +26,7 @@ Author: Danial Behzadi <dani.behzi@ubuntu.com>
<!-- interface-license-type gplv3 -->
<!-- interface-name Carburetor -->
<!-- interface-description Settings for Tractor -->
<!-- interface-copyright 2019 - 202
0
-->
<!-- interface-copyright 2019 - 202
1
-->
<!-- interface-authors Danial Behzadi <dani.behzi@ubuntu.com> -->
<object
class=
"GtkAboutDialog"
id=
"AboutDialog"
>
<property
name=
"can-focus"
>
False
</property>
...
...
@@ -34,7 +34,7 @@ Author: Danial Behzadi <dani.behzi@ubuntu.com>
<property
name=
"icon-name"
>
carburetor
</property>
<property
name=
"type-hint"
>
dialog
</property>
<property
name=
"program-name"
>
Carburetor
</property>
<property
name=
"copyright"
translatable=
"yes"
>
Copyright © 2019-202
0
, Tractor Team
</property>
<property
name=
"copyright"
translatable=
"yes"
>
Copyright © 2019-202
1
, Tractor Team
</property>
<property
name=
"comments"
translatable=
"yes"
>
Settings for Tractor
</property>
<property
name=
"website"
>
https://framagit.org/tractor/carburetor/
</property>
<property
name=
"website-label"
translatable=
"yes"
>
Source Code
</property>
...
...
carburetor/actions.py
View file @
ad2c1987
#!/usr/bin/python3
# Released under GPLv3+ License
# Danial Behzadi<dani.behzi@ubuntu.com>, 2020
# Danial Behzadi<dani.behzi@ubuntu.com>, 2020
-2021.
import
gi
import
os
...
...
@@ -12,9 +12,6 @@ from . import config
from
.
import
functions
from
.
import
ui
command
=
"tractor "
_
=
config
.
_
app_name
=
config
.
app_name
def
add
(
name
,
function
,
app
):
action
=
Gio
.
SimpleAction
.
new
(
name
,
None
)
...
...
@@ -63,24 +60,29 @@ def on_connect(action, param, app):
app
.
spinner
.
show
()
main_label
=
ui
.
get
(
'MainLabel'
)
if
functions
.
is_running
():
text_stopping
=
_
(
"Disconnecting…"
)
text_stopping
=
config
.
_
(
"Disconnecting…"
)
main_label
.
set_label
(
text_stopping
)
action
=
'stop'
else
:
text_starting
=
_
(
"Connecting…"
)
text_starting
=
config
.
_
(
"Connecting…"
)
main_label
.
set_label
(
text_starting
)
action
=
'start'
app
.
task
=
Popen
(
command
+
action
,
stdout
=
PIPE
,
shell
=
True
,
preexec_fn
=
os
.
setsid
)
app
.
io_id
=
GLib
.
io_add_watch
(
app
.
task
.
stdout
,
GLib
.
IO_IN
,
functions
.
set_progress
)
GLib
.
io_add_watch
(
app
.
task
.
stdout
,
GLib
.
IO_HUP
,
functions
.
thread_finished
,
button
,
app
)
app
.
task
=
Popen
(
config
.
command
+
action
,
stdout
=
PIPE
,
shell
=
True
,
preexec_fn
=
os
.
setsid
)
app
.
io_id
=
GLib
.
io_add_watch
(
app
.
task
.
stdout
,
GLib
.
IO_IN
,
functions
.
set_progress
)
GLib
.
io_add_watch
(
app
.
task
.
stdout
,
GLib
.
IO_HUP
,
functions
.
thread_finished
,
button
,
app
)
def
on_new_id
(
action
,
param
,
app
):
if
functions
.
is_running
():
newid
=
Popen
(
command
+
'newid'
,
stdout
=
PIPE
,
shell
=
True
)
newid
=
Popen
(
config
.
command
+
'newid'
,
stdout
=
PIPE
,
shell
=
True
)
newid
.
wait
()
notif
=
Notify
.
Notification
.
new
(
app_name
,
_
(
"You have a new identity!"
))
notif
=
Notify
.
Notification
.
new
(
config
.
app_name
,
config
.
_
(
"You have a new identity!"
))
else
:
notif
=
Notify
.
Notification
.
new
(
app_name
,
_
(
"Tractor is not running!"
))
notif
=
Notify
.
Notification
.
new
(
config
.
app_name
,
config
.
_
(
"Tractor is not running!"
))
notif
.
set_timeout
(
Notify
.
EXPIRES_DEFAULT
)
notif
.
show
()
...
...
@@ -90,7 +92,7 @@ def on_set_proxy(action, param, app):
action
=
'set'
else
:
action
=
'unset'
task
=
Popen
(
command
+
action
,
stdout
=
PIPE
,
shell
=
True
)
task
=
Popen
(
config
.
command
+
action
,
stdout
=
PIPE
,
shell
=
True
)
task
.
wait
()
def
on_save
(
action
,
param
,
app
):
...
...
@@ -98,7 +100,8 @@ def on_save(action, param, app):
buff
=
textview
.
get_buffer
()
text
=
buff
.
get_text
(
buff
.
get_start_iter
(),
buff
.
get_end_iter
(),
0
)
regex
=
re
.
compile
(
r
'^( )*([Bb][Rr][Ii][Dd][Gg][Ee])?( )*'
,
re
.
MULTILINE
)
get_bridges
=
Popen
(
command
+
"bridgesfile"
,
stdout
=
PIPE
,
shell
=
True
)
get_bridges
=
Popen
(
config
.
command
+
"bridgesfile"
,
stdout
=
PIPE
,
shell
=
True
)
bridges
=
get_bridges
.
stdout
.
read
()
bridges_file
=
bridges
.
decode
(
"utf-8"
).
strip
(
'
\n
'
)
if
text
==
regex
.
sub
(
'Bridge '
,
text
):
...
...
carburetor/carburetor.py
View file @
ad2c1987
#!/usr/bin/python3
# Released under GPLv3+ License
# Danial Behzadi<dani.behzi@ubuntu.com>, 2019-202
0
# Danial Behzadi<dani.behzi@ubuntu.com>, 2019-202
1.
import
gi
gi
.
require_versions
({
'Gtk'
:
'3.0'
})
...
...
@@ -12,7 +12,8 @@ from . import actions
class
Application
(
Gtk
.
Application
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
application_id
=
'org.tractor.carburetor'
,
**
kwargs
)
super
().
__init__
(
*
args
,
application_id
=
'org.tractor.carburetor'
,
**
kwargs
)
self
.
window
=
None
self
.
prefs
=
None
self
.
about
=
None
...
...
carburetor/config.py
View file @
ad2c1987
#!/usr/bin/python3
# Released under GPLv3+ License
# Danial Behzadi<dani.behzi@ubuntu.com>, 2020
# Danial Behzadi<dani.behzi@ubuntu.com>, 2020
-2021.
import
gettext
import
gi
...
...
@@ -17,6 +17,7 @@ locale.bindtextdomain('messages', locale_dir)
gettext
.
bindtextdomain
(
'messages'
,
locale_dir
)
gettext
.
textdomain
(
'messages'
)
_
=
gettext
.
gettext
command
=
"tractor "
app_name
=
_
(
"Carburetor"
)
app_comment
=
_
(
"Settings for Tractor"
)
version
=
"3.2"
...
...
carburetor/functions.py
View file @
ad2c1987
#!/usr/bin/python3
# Released under GPLv3+ License
# Danial Behzadi<dani.behzi@ubuntu.com>, 2020
# Danial Behzadi<dani.behzi@ubuntu.com>, 2020
-2021.
import
gi
import
re
...
...
@@ -11,13 +11,9 @@ from subprocess import PIPE, Popen
from
.
import
config
from
.
import
ui
command
=
"tractor "
dconf
=
config
.
dconf
_
=
config
.
_
app_name
=
config
.
app_name
def
is_running
():
check
=
Popen
(
command
+
'isrunning'
,
stdout
=
PIPE
,
shell
=
True
)
check
=
Popen
(
config
.
command
+
'isrunning'
,
stdout
=
PIPE
,
shell
=
True
)
output
=
strtobool
(
check
.
stdout
.
read
().
decode
(
'utf-8'
).
strip
(
'
\n
'
))
return
output
...
...
@@ -44,7 +40,7 @@ def thread_finished (stdout, condition, button, app):
return
False
def
notify
(
app
):
notif
=
Notify
.
Notification
.
new
(
app_name
,
app
.
notification
)
notif
=
Notify
.
Notification
.
new
(
config
.
app_name
,
app
.
notification
)
notif
.
set_timeout
(
Notify
.
EXPIRES_DEFAULT
)
notif
.
show
()
...
...
@@ -54,9 +50,9 @@ def set_to_stopped(app):
image
.
set_from_icon_name
(
'process-stop'
,
Gtk
.
IconSize
.
DIALOG
)
image
.
show
()
label
=
ui
.
get
(
'MainLabel'
)
label
.
set_label
(
_
(
"Stopped"
))
label
.
set_label
(
config
.
_
(
"Stopped"
))
button
=
ui
.
get
(
'ConnectButton'
)
text_start
=
_
(
"_Connect"
)
text_start
=
config
.
_
(
"_Connect"
)
button
.
set_label
(
text_start
)
style
=
button
.
get_style_context
()
style
.
remove_class
(
'red'
)
...
...
@@ -64,16 +60,16 @@ def set_to_stopped(app):
button
=
ui
.
get
(
'ActionMenuButton'
)
button
.
set_sensitive
(
False
)
if
app
:
app
.
notification
=
_
(
"Tractor is stopped"
)
app
.
notification
=
config
.
_
(
"Tractor is stopped"
)
def
set_to_running
(
app
):
image
=
ui
.
get
(
'MainImage'
)
image
.
set_from_icon_name
(
'security-high'
,
Gtk
.
IconSize
.
DIALOG
)
image
.
show
()
label
=
ui
.
get
(
'MainLabel'
)
label
.
set_label
(
_
(
"Running"
))
label
.
set_label
(
config
.
_
(
"Running"
))
button
=
ui
.
get
(
'ConnectButton'
)
text_stop
=
_
(
"_Disconnect"
)
text_stop
=
config
.
_
(
"_Disconnect"
)
style
=
button
.
get_style_context
()
style
.
remove_class
(
'green'
)
style
.
add_class
(
'red'
)
...
...
@@ -81,7 +77,7 @@ def set_to_running(app):
button
=
ui
.
get
(
'ActionMenuButton'
)
button
.
set_sensitive
(
True
)
if
app
:
app
.
notification
=
_
(
"Tractor is running"
)
app
.
notification
=
config
.
_
(
"Tractor is running"
)
def
set_run_status
(
app
):
if
is_running
():
...
...
@@ -96,13 +92,13 @@ def hide_window(window, data):
def
is_proxy_set
():
proxy
=
Gio
.
Settings
.
new
(
'org.gnome.system.proxy'
)
socks
=
Gio
.
Settings
.
new
(
'org.gnome.system.proxy.socks'
)
if
dconf
.
get_boolean
(
'accept-connection'
):
if
config
.
dconf
.
get_boolean
(
'accept-connection'
):
ip
=
'0.0.0.0'
else
:
ip
=
'127.0.0.1'
proxy_mode
=
proxy
.
get_string
(
'mode'
)
current_port
=
socks
.
get_int
(
'port'
)
tractor_port
=
dconf
.
get_int
(
'socks-port'
)
tractor_port
=
config
.
dconf
.
get_int
(
'socks-port'
)
current_ip
=
socks
.
get_string
(
'host'
)
if
proxy_mode
==
'manual'
and
current_port
==
tractor_port
and
current_ip
==
ip
:
return
True
...
...
carburetor/handler.py
View file @
ad2c1987
#!/usr/bin/python3
# Released under GPLv3+ License
# Danial Behzadi<dani.behzi@ubuntu.com>, 2020
# Danial Behzadi<dani.behzi@ubuntu.com>, 2020
-2021.
import
gi
from
gi.repository
import
Gio
,
Gtk
...
...
@@ -10,12 +10,6 @@ from . import config
from
.
import
functions
from
.
import
ui
command
=
"tractor "
dconf
=
config
.
dconf
_
=
config
.
_
app_name
=
config
.
app_name
version
=
config
.
version
class
Handler
:
def
on_MainBox_realize
(
self
,
box
):
...
...
@@ -25,6 +19,7 @@ class Handler:
functions
.
set_checkbox
()
def
on_ActionExitNode_realize
(
self
,
combo
):
_
=
config
.
_
nodes
=
{
_
(
"Austria"
):
"au"
,
_
(
"Bulgaria"
):
"bg"
,
_
(
"Canada"
):
"ca"
,
...
...
@@ -50,38 +45,48 @@ class Handler:
combo
.
append
(
"ww"
,
_
(
"Auto (Best)"
))
for
node
in
sorted
(
nodes
.
keys
()):
combo
.
append
(
nodes
[
node
],
node
)
dconf
.
bind
(
"exit-node"
,
combo
,
"active-id"
,
Gio
.
SettingsBindFlags
.
DEFAULT
)
config
.
dconf
.
bind
(
"exit-node"
,
combo
,
"active-id"
,
Gio
.
SettingsBindFlags
.
DEFAULT
)
def
on_ActionAcceptConnection_realize
(
self
,
switch
):
dconf
.
bind
(
"accept-connection"
,
switch
,
"active"
,
Gio
.
SettingsBindFlags
.
DEFAULT
)
config
.
dconf
.
bind
(
"accept-connection"
,
switch
,
"active"
,
Gio
.
SettingsBindFlags
.
DEFAULT
)
def
on_ActionSocksPort_realize
(
self
,
spin
):
port
=
dconf
.
get_int
(
"socks-port"
)
adjustment
=
Gtk
.
Adjustment
(
value
=
port
,
lower
=
1
,
upper
=
65535
,
step_increment
=
1
,
page_increment
=
1
,
page_size
=
0
)
port
=
config
.
dconf
.
get_int
(
"socks-port"
)
adjustment
=
Gtk
.
Adjustment
(
value
=
port
,
lower
=
1
,
upper
=
65535
,
step_increment
=
1
,
page_increment
=
1
,
page_size
=
0
)
spin
.
set_adjustment
(
adjustment
)
spin
.
set_text
(
str
(
port
))
dconf
.
bind
(
"socks-port"
,
spin
,
"value"
,
Gio
.
SettingsBindFlags
.
DEFAULT
)
config
.
dconf
.
bind
(
"socks-port"
,
spin
,
"value"
,
Gio
.
SettingsBindFlags
.
DEFAULT
)
def
on_ActionDNSPort_realize
(
self
,
spin
):
port
=
dconf
.
get_int
(
"dns-port"
)
adjustment
=
Gtk
.
Adjustment
(
value
=
port
,
lower
=
1
,
upper
=
65535
,
step_increment
=
1
,
page_increment
=
1
,
page_size
=
0
)
port
=
config
.
dconf
.
get_int
(
"dns-port"
)
adjustment
=
Gtk
.
Adjustment
(
value
=
port
,
lower
=
1
,
upper
=
65535
,
step_increment
=
1
,
page_increment
=
1
,
page_size
=
0
)
spin
.
set_adjustment
(
adjustment
)
spin
.
set_text
(
str
(
port
))
dconf
.
bind
(
"dns-port"
,
spin
,
"value"
,
Gio
.
SettingsBindFlags
.
DEFAULT
)
config
.
dconf
.
bind
(
"dns-port"
,
spin
,
"value"
,
Gio
.
SettingsBindFlags
.
DEFAULT
)
def
on_ActionHTTPPort_realize
(
self
,
spin
):
port
=
dconf
.
get_int
(
"http-port"
)
adjustment
=
Gtk
.
Adjustment
(
value
=
port
,
lower
=
1
,
upper
=
65535
,
step_increment
=
1
,
page_increment
=
1
,
page_size
=
0
)
port
=
config
.
dconf
.
get_int
(
"http-port"
)
adjustment
=
Gtk
.
Adjustment
(
value
=
port
,
lower
=
1
,
upper
=
65535
,
step_increment
=
1
,
page_increment
=
1
,
page_size
=
0
)
spin
.
set_adjustment
(
adjustment
)
spin
.
set_text
(
str
(
port
))
dconf
.
bind
(
"http-port"
,
spin
,
"value"
,
Gio
.
SettingsBindFlags
.
DEFAULT
)
config
.
dconf
.
bind
(
"http-port"
,
spin
,
"value"
,
Gio
.
SettingsBindFlags
.
DEFAULT
)
def
on_ActionBridgeType_realize
(
self
,
switch
):
dconf
.
bind
(
"use-bridges"
,
switch
,
"active"
,
Gio
.
SettingsBindFlags
.
DEFAULT
)
config
.
dconf
.
bind
(
"use-bridges"
,
switch
,
"active"
,
Gio
.
SettingsBindFlags
.
DEFAULT
)
def
on_TextO4Bridge_realize
(
self
,
view
):
buff
=
view
.
get_buffer
()
get_bridges
=
Popen
(
command
+
"bridgesfile"
,
stdout
=
PIPE
,
shell
=
True
)
get_bridges
=
Popen
(
config
.
command
+
"bridgesfile"
,
stdout
=
PIPE
,
shell
=
True
)
bridges
=
get_bridges
.
stdout
.
read
()
bridges_file
=
bridges
.
decode
(
"utf-8"
).
strip
(
'
\n
'
)
with
open
(
bridges_file
)
as
file
:
...
...
@@ -92,6 +97,7 @@ class Handler:
actions
.
on_save
(
button
,
None
,
self
)
def
on_ActionBridgePlugin_realize
(
self
,
chooser
):
dconf
=
config
.
dconf
def
on_file_set
(
chooser
):
filename
=
chooser
.
get_filename
()
dconf
.
set_string
(
"obfs4-path"
,
filename
)
...
...
@@ -100,10 +106,9 @@ class Handler:
chooser
.
connect
(
"file-set"
,
on_file_set
)
def
on_AboutDialog_realize
(
self
,
dialog
):
dialog
.
set_program_name
(
app_name
)
dialog
.
set_version
(
version
)
dialog
.
set_translator_credits
(
_
(
"translator-credits"
))
dialog
.
set_program_name
(
config
.
app_name
)
dialog
.
set_version
(
config
.
version
)
dialog
.
set_translator_credits
(
config
.
_
(
"translator-credits"
))
def
on_AboutDialog_destroy
(
self
,
dialog
):
dialog
.
hide
()
carburetor/ui.py
View file @
ad2c1987
#!/usr/bin/python3
# Released under GPLv3+ License
# Danial Behzadi<dani.behzi@ubuntu.com>, 2020
# Danial Behzadi<dani.behzi@ubuntu.com>, 2020
-2021.
import
gi
import
os
...
...
@@ -9,10 +9,11 @@ from gi.repository import Gdk, GLib, Gtk
from
.
import
config
from
.
import
handler
s_data_dir
=
config
.
s_data_dir
builder
=
Gtk
.
Builder
()
def
initialize_builder
():
s_data_dir
=
config
.
s_data_dir
builder
.
add_from_file
(
s_data_dir
+
'/about.ui'
)
builder
.
add_from_file
(
s_data_dir
+
'/main.ui'
)
builder
.
add_from_file
(
s_data_dir
+
'/preferences.ui'
)
...
...
@@ -23,7 +24,8 @@ def get(obj):
def
css
():
css_provider
=
Gtk
.
CssProvider
()
css_provider
.
load_from_path
(
s_data_dir
+
'/style.css'
)
css_provider
.
load_from_path
(
config
.
s_data_dir
+
'/style.css'
)
screen
=
Gdk
.
Screen
.
get_default
()
context
=
Gtk
.
StyleContext
()
context
.
add_provider_for_screen
(
screen
,
css_provider
,
Gtk
.
STYLE_PROVIDER_PRIORITY_USER
)
context
.
add_provider_for_screen
(
screen
,
css_provider
,
Gtk
.
STYLE_PROVIDER_PRIORITY_USER
)
debian/changelog
View file @
ad2c1987
carburetor (3.3) groovy; urgency=medium
* Cleanup source code based on pep-8
-- Danial Behzadi <dani.behzi@ubuntu.com> Thu, 25 Mar 2021 20:10:00 +0430
carburetor (3.2) focal; urgency=medium
* Main window uses libhandy now
...
...
debian/copyright
View file @
ad2c1987
Carburetor - Settings app for Tractor
Copyright 2018 Danial Behzadi <dani.behzi@ubuntu.com>
Copyright 2018
-2021
Danial Behzadi <dani.behzi@ubuntu.com>
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Source: https://gitlab.com/tractor-team/carburetor
License: GPL-3
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment