Fix improper dos line endings
This commit is contained in:
parent
7c2a2af1f0
commit
a110ad1d20
|
@ -138,13 +138,13 @@ def load_commands(command_dir, exclude=[]):
|
||||||
class ConsoleUI(component.Component):
|
class ConsoleUI(component.Component):
|
||||||
def __init__(self, args=None):
|
def __init__(self, args=None):
|
||||||
component.Component.__init__(self, "ConsoleUI", 2)
|
component.Component.__init__(self, "ConsoleUI", 2)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
locale.setlocale(locale.LC_ALL, '')
|
locale.setlocale(locale.LC_ALL, '')
|
||||||
self.encoding = locale.getpreferredencoding()
|
self.encoding = locale.getpreferredencoding()
|
||||||
except:
|
except:
|
||||||
self.encoding = sys.getdefaultencoding()
|
self.encoding = sys.getdefaultencoding()
|
||||||
|
|
||||||
log.debug("Using encoding: %s", self.encoding)
|
log.debug("Using encoding: %s", self.encoding)
|
||||||
# Load all the commands
|
# Load all the commands
|
||||||
self._commands = load_commands(os.path.join(UI_PATH, 'commands'))
|
self._commands = load_commands(os.path.join(UI_PATH, 'commands'))
|
||||||
|
|
|
@ -115,7 +115,7 @@ class Screen(CursesStdIO):
|
||||||
self.encoding = sys.getdefaultencoding()
|
self.encoding = sys.getdefaultencoding()
|
||||||
else:
|
else:
|
||||||
self.encoding = encoding
|
self.encoding = encoding
|
||||||
|
|
||||||
# Do a refresh right away to draw the screen
|
# Do a refresh right away to draw the screen
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
|
@ -239,8 +239,8 @@ class Screen(CursesStdIO):
|
||||||
if index + 1 == len(parsed):
|
if index + 1 == len(parsed):
|
||||||
# This is the last string so lets append some " " to it
|
# This is the last string so lets append some " " to it
|
||||||
s += " " * (self.cols - (col + len(s)) - 1)
|
s += " " * (self.cols - (col + len(s)) - 1)
|
||||||
if isinstance(s, unicode):
|
if isinstance(s, unicode):
|
||||||
#Have to use replace as character counting has already been done
|
#Have to use replace as character counting has already been done
|
||||||
s = s.encode(self.encoding, 'replace')
|
s = s.encode(self.encoding, 'replace')
|
||||||
self.stdscr.addstr(row, col, s, color)
|
self.stdscr.addstr(row, col, s, color)
|
||||||
col += len(s)
|
col += len(s)
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import locale
|
import locale
|
||||||
import shutil
|
import shutil
|
||||||
import urllib
|
import urllib
|
||||||
import gettext
|
import gettext
|
||||||
import hashlib
|
import hashlib
|
||||||
|
@ -82,20 +82,20 @@ CONFIG_DEFAULTS = {
|
||||||
# Misc Settings
|
# Misc Settings
|
||||||
"enabled_plugins": [],
|
"enabled_plugins": [],
|
||||||
"default_daemon": "",
|
"default_daemon": "",
|
||||||
|
|
||||||
# Auth Settings
|
# Auth Settings
|
||||||
"pwd_salt": "c26ab3bbd8b137f99cd83c2c1c0963bcc1a35cad",
|
"pwd_salt": "c26ab3bbd8b137f99cd83c2c1c0963bcc1a35cad",
|
||||||
"pwd_sha1": "2ce1a410bcdcc53064129b6d950f2e9fee4edc1e",
|
"pwd_sha1": "2ce1a410bcdcc53064129b6d950f2e9fee4edc1e",
|
||||||
"session_timeout": 3600,
|
"session_timeout": 3600,
|
||||||
"sessions": {},
|
"sessions": {},
|
||||||
|
|
||||||
# UI Settings
|
# UI Settings
|
||||||
"sidebar_show_zero": False,
|
"sidebar_show_zero": False,
|
||||||
"sidebar_show_trackers": False,
|
"sidebar_show_trackers": False,
|
||||||
"show_session_speed": False,
|
"show_session_speed": False,
|
||||||
"show_sidebar": True,
|
"show_sidebar": True,
|
||||||
"theme": "slate",
|
"theme": "slate",
|
||||||
|
|
||||||
# Server Settings
|
# Server Settings
|
||||||
"port": 8112,
|
"port": 8112,
|
||||||
"https": False,
|
"https": False,
|
||||||
|
@ -245,17 +245,17 @@ class LookupResource(resource.Resource, component.Component):
|
||||||
def __init__(self, name, *directories):
|
def __init__(self, name, *directories):
|
||||||
resource.Resource.__init__(self)
|
resource.Resource.__init__(self)
|
||||||
component.Component.__init__(self, name)
|
component.Component.__init__(self, name)
|
||||||
|
|
||||||
self.__paths = {}
|
self.__paths = {}
|
||||||
for directory in directories:
|
for directory in directories:
|
||||||
self.addDirectory(directory)
|
self.addDirectory(directory)
|
||||||
|
|
||||||
def addDirectory(self, directory, path=""):
|
def addDirectory(self, directory, path=""):
|
||||||
log.debug("Adding directory `%s` with path `%s`", directory, path)
|
log.debug("Adding directory `%s` with path `%s`", directory, path)
|
||||||
paths = self.__paths.get(path, [])
|
paths = self.__paths.get(path, [])
|
||||||
paths.append(directory)
|
paths.append(directory)
|
||||||
self.__paths[path] = paths
|
self.__paths[path] = paths
|
||||||
|
|
||||||
def removeDirectory(self, directory, path=""):
|
def removeDirectory(self, directory, path=""):
|
||||||
log.debug("Removing directory `%s`", directory)
|
log.debug("Removing directory `%s`", directory)
|
||||||
self.__paths[path].remove(directory)
|
self.__paths[path].remove(directory)
|
||||||
|
@ -267,23 +267,23 @@ class LookupResource(resource.Resource, component.Component):
|
||||||
request.lookup_path = path
|
request.lookup_path = path
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def render(self, request):
|
def render(self, request):
|
||||||
log.debug("Requested path: '%s'", request.lookup_path)
|
log.debug("Requested path: '%s'", request.lookup_path)
|
||||||
path = os.path.dirname(request.lookup_path)
|
path = os.path.dirname(request.lookup_path)
|
||||||
|
|
||||||
if path not in self.__paths:
|
if path not in self.__paths:
|
||||||
request.setResponseCode(http.NOT_FOUND)
|
request.setResponseCode(http.NOT_FOUND)
|
||||||
return "<h1>404 - Not Found</h1>"
|
return "<h1>404 - Not Found</h1>"
|
||||||
|
|
||||||
filename = os.path.basename(request.path)
|
filename = os.path.basename(request.path)
|
||||||
for directory in self.__paths[path]:
|
for directory in self.__paths[path]:
|
||||||
if filename in os.listdir(directory):
|
if filename in os.listdir(directory):
|
||||||
path = os.path.join(directory, filename)
|
path = os.path.join(directory, filename)
|
||||||
log.debug("Serving path: '%s'", path)
|
log.debug("Serving path: '%s'", path)
|
||||||
mime_type = mimetypes.guess_type(path)
|
mime_type = mimetypes.guess_type(path)
|
||||||
request.setHeader("content-type", mime_type[0])
|
request.setHeader("content-type", mime_type[0])
|
||||||
return open(path, "rb").read()
|
return open(path, "rb").read()
|
||||||
|
|
||||||
request.setResponseCode(http.NOT_FOUND)
|
request.setResponseCode(http.NOT_FOUND)
|
||||||
return "<h1>404 - Not Found</h1>"
|
return "<h1>404 - Not Found</h1>"
|
||||||
|
|
||||||
|
@ -383,29 +383,29 @@ class TopLevel(resource.Resource):
|
||||||
@property
|
@property
|
||||||
def stylesheets(self):
|
def stylesheets(self):
|
||||||
return self.__stylesheets
|
return self.__stylesheets
|
||||||
|
|
||||||
def add_script(self, script):
|
def add_script(self, script):
|
||||||
"""
|
"""
|
||||||
Adds a script to the server so it is included in the <head> element
|
Adds a script to the server so it is included in the <head> element
|
||||||
of the index page.
|
of the index page.
|
||||||
|
|
||||||
:param script: The path to the script
|
:param script: The path to the script
|
||||||
:type script: string
|
:type script: string
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.__scripts.append(script)
|
self.__scripts.append(script)
|
||||||
self.__debug_scripts.append(script)
|
self.__debug_scripts.append(script)
|
||||||
|
|
||||||
def remove_script(self, script):
|
def remove_script(self, script):
|
||||||
"""
|
"""
|
||||||
Removes a script from the server.
|
Removes a script from the server.
|
||||||
|
|
||||||
:param script: The path to the script
|
:param script: The path to the script
|
||||||
:type script: string
|
:type script: string
|
||||||
"""
|
"""
|
||||||
self.__scripts.remove(script)
|
self.__scripts.remove(script)
|
||||||
self.__debug_scripts.remove(script)
|
self.__debug_scripts.remove(script)
|
||||||
|
|
||||||
|
|
||||||
def getChild(self, path, request):
|
def getChild(self, path, request):
|
||||||
if path == "":
|
if path == "":
|
||||||
|
@ -421,7 +421,7 @@ class TopLevel(resource.Resource):
|
||||||
debug = True
|
debug = True
|
||||||
elif debug_arg == 'false':
|
elif debug_arg == 'false':
|
||||||
debug = False
|
debug = False
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
scripts = self.debug_scripts[:]
|
scripts = self.debug_scripts[:]
|
||||||
else:
|
else:
|
||||||
|
@ -432,7 +432,7 @@ class TopLevel(resource.Resource):
|
||||||
return template.render(scripts=scripts, stylesheets=self.stylesheets, debug=debug)
|
return template.render(scripts=scripts, stylesheets=self.stylesheets, debug=debug)
|
||||||
|
|
||||||
class ServerContextFactory:
|
class ServerContextFactory:
|
||||||
|
|
||||||
def getContext(self):
|
def getContext(self):
|
||||||
"""Creates an SSL context."""
|
"""Creates an SSL context."""
|
||||||
ctx = SSL.Context(SSL.SSLv3_METHOD)
|
ctx = SSL.Context(SSL.SSLv3_METHOD)
|
||||||
|
@ -449,7 +449,7 @@ class DelugeWeb(component.Component):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(DelugeWeb, self).__init__("DelugeWeb")
|
super(DelugeWeb, self).__init__("DelugeWeb")
|
||||||
self.config = configmanager.ConfigManager("web.conf", CONFIG_DEFAULTS)
|
self.config = configmanager.ConfigManager("web.conf", CONFIG_DEFAULTS)
|
||||||
|
|
||||||
# Check to see if a configuration from the web interface prior to 1.2
|
# Check to see if a configuration from the web interface prior to 1.2
|
||||||
# exists and convert it over.
|
# exists and convert it over.
|
||||||
if os.path.exists(configmanager.get_config_dir("webui06.conf")):
|
if os.path.exists(configmanager.get_config_dir("webui06.conf")):
|
||||||
|
@ -460,13 +460,13 @@ class DelugeWeb(component.Component):
|
||||||
# it.
|
# it.
|
||||||
for key in OLD_CONFIG_KEYS:
|
for key in OLD_CONFIG_KEYS:
|
||||||
self.config[key] = old_config[key]
|
self.config[key] = old_config[key]
|
||||||
|
|
||||||
# We need to base64 encode the passwords since json can't handle
|
# We need to base64 encode the passwords since json can't handle
|
||||||
# them otherwise.
|
# them otherwise.
|
||||||
from base64 import encodestring
|
from base64 import encodestring
|
||||||
self.config["old_pwd_md5"] = encodestring(old_config["pwd_md5"])
|
self.config["old_pwd_md5"] = encodestring(old_config["pwd_md5"])
|
||||||
self.config["old_pwd_salt"] = encodestring(old_config["pwd_salt"])
|
self.config["old_pwd_salt"] = encodestring(old_config["pwd_salt"])
|
||||||
|
|
||||||
# Save our config and if it saved successfully then rename the
|
# Save our config and if it saved successfully then rename the
|
||||||
# old configuration file.
|
# old configuration file.
|
||||||
if self.config.save():
|
if self.config.save():
|
||||||
|
@ -487,7 +487,7 @@ class DelugeWeb(component.Component):
|
||||||
|
|
||||||
# Initalize the plugins
|
# Initalize the plugins
|
||||||
self.plugins = PluginManager()
|
self.plugins = PluginManager()
|
||||||
|
|
||||||
def install_signal_handlers(self):
|
def install_signal_handlers(self):
|
||||||
# Since twisted assigns itself all the signals may as well make
|
# Since twisted assigns itself all the signals may as well make
|
||||||
# use of it.
|
# use of it.
|
||||||
|
@ -512,29 +512,29 @@ class DelugeWeb(component.Component):
|
||||||
self.start_ssl()
|
self.start_ssl()
|
||||||
else:
|
else:
|
||||||
self.start_normal()
|
self.start_normal()
|
||||||
|
|
||||||
component.get("JSON").enable()
|
component.get("JSON").enable()
|
||||||
|
|
||||||
if start_reactor:
|
if start_reactor:
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
||||||
def start_normal(self):
|
def start_normal(self):
|
||||||
self.socket = reactor.listenTCP(self.port, self.site)
|
self.socket = reactor.listenTCP(self.port, self.site)
|
||||||
log.info("serving on %s:%s view at http://127.0.0.1:%s", "0.0.0.0",
|
log.info("serving on %s:%s view at http://127.0.0.1:%s", "0.0.0.0",
|
||||||
self.port, self.port)
|
self.port, self.port)
|
||||||
|
|
||||||
def start_ssl(self):
|
def start_ssl(self):
|
||||||
check_ssl_keys()
|
check_ssl_keys()
|
||||||
self.socket = reactor.listenSSL(self.port, self.site, ServerContextFactory())
|
self.socket = reactor.listenSSL(self.port, self.site, ServerContextFactory())
|
||||||
log.info("serving on %s:%s view at https://127.0.0.1:%s", "0.0.0.0",
|
log.info("serving on %s:%s view at https://127.0.0.1:%s", "0.0.0.0",
|
||||||
self.port, self.port)
|
self.port, self.port)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
log.info("Shutting down webserver")
|
log.info("Shutting down webserver")
|
||||||
self.plugins.disable_plugins()
|
self.plugins.disable_plugins()
|
||||||
log.debug("Saving configuration file")
|
log.debug("Saving configuration file")
|
||||||
self.config.save()
|
self.config.save()
|
||||||
|
|
||||||
if self.socket:
|
if self.socket:
|
||||||
d = self.socket.stopListening()
|
d = self.socket.stopListening()
|
||||||
self.socket = None
|
self.socket = None
|
||||||
|
@ -544,10 +544,10 @@ class DelugeWeb(component.Component):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def shutdown(self, *args):
|
def shutdown(self, *args):
|
||||||
self.stop()
|
self.stop()
|
||||||
try:
|
try:
|
||||||
reactor.stop()
|
reactor.stop()
|
||||||
except error.ReactorNotRunning:
|
except error.ReactorNotRunning:
|
||||||
log.debug("Reactor not running")
|
log.debug("Reactor not running")
|
||||||
|
|
||||||
if __name__ == "__builtin__":
|
if __name__ == "__builtin__":
|
||||||
|
|
Loading…
Reference in New Issue