[entropy] drop repository manager code, R.I.P.

This commit is contained in:
Fabio Erculiani
2011-02-09 19:22:20 +01:00
parent 3e2136024e
commit df3bb8005d
37 changed files with 21510 additions and 31957 deletions
+1 -4
View File
@@ -1,7 +1,7 @@
PKGNAME = entropy
PYTHON = python2
SUBDIRS = magneto misc/po sulfur
SERVER_INSPKGS = reagent.py activator.py server_reagent.py server_activator.py repository-admin-daemon repository-services-daemon.example server_query.py
SERVER_INSPKGS = reagent.py activator.py server_reagent.py server_activator.py repository-services-daemon.example server_query.py
PREFIX = /usr
BINDIR = $(PREFIX)/bin
LIBDIR = $(PREFIX)/lib
@@ -25,10 +25,8 @@ entropy-install:
mkdir -p $(DESTDIR)/$(LIBDIR)/entropy/services
cp libraries/entropy $(DESTDIR)/$(LIBDIR)/entropy/libraries/ -Ra
install -m 755 services/repository-admin-daemon $(DESTDIR)$(PREFIX)/sbin/
install -m 755 services/repository-services-daemon.example $(DESTDIR)$(PREFIX)/sbin/
install -m 755 misc/entropy.sh $(DESTDIR)$(PREFIX)/sbin/
install -m 755 services/repository_admin $(DESTDIR)/etc/init.d/
install -m 755 services/repository_services $(DESTDIR)/etc/init.d/
install -m 755 services/smartapp_wrapper $(DESTDIR)/$(LIBDIR)/entropy/services/
install -m 755 misc/entropy_hwgen.sh $(DESTDIR)$(BINDIR)/
@@ -82,7 +80,6 @@ equo-install:
install -m 644 client/*.py $(DESTDIR)/$(LIBDIR)/entropy/client/
install -m 644 client/revision $(DESTDIR)/$(LIBDIR)/entropy/client/
install -m 644 client/entropy-system-test-client $(DESTDIR)/$(LIBDIR)/entropy/client/
install -m 755 client/equo.py $(DESTDIR)/$(LIBDIR)/entropy/client/
install -m 755 services/kernel-switcher $(DESTDIR)$(BINDIR)/
-23
View File
@@ -1,23 +0,0 @@
import sys
sys.path.insert(0,'../libraries')
from entropy.client.services.system.interfaces import Client as SystemSocketClientInterface
from entropy.client.services.ugc.commands import Client as RepositorySocketClientCommands
from entropy.client.interfaces import Client as EquoInterface
from entropyConstants import *
repository = 'sabayonlinux.org'
Entropy = EquoInterface()
dburl = Entropy.Settings()['repositories']['available'][repository]['service_uri']
port = Entropy.Settings()['repositories']['available'][repository]['service_port']
ssl_ca_cert = "/etc/entropy/certs/sabayonlinux.org.crt"
ssl_cert = "/etc/entropy/certs/sabayonlinux.org.server.crt"
eapi3_socket = SystemSocketClientInterface(Entropy, RepositorySocketClientCommands, ssl = True)# , server_ca_cert = ssl_ca_cert, server_cert = ssl_cert)
eapi3_socket.connect(dburl, port+1)
username = 'lxnay'
password = 'xxxx'
session_id = eapi3_socket.open_session()
print "logged in?",eapi3_socket.CmdInterface.service_login(username, password, session_id)
print "logging out...",eapi3_socket.CmdInterface.service_logout(username, session_id)
eapi3_socket.close_session(session_id)
eapi3_socket.disconnect()
-30
View File
@@ -1,30 +0,0 @@
import sys
sys.path.insert(0,'../libraries')
from entropy.client.services.system.interfaces import Client as SystemManagerClientInterface
from entropy.client.services.system.commands import Repository as SystemManagerRepositoryClientCommands
from entropy.client.services.system.methods import Repository as SystemManagerRepositoryMethodsInterface
from entropy.client.interfaces import Client as EquoInterface
from entropyConstants import *
Entropy = EquoInterface()
cli_srv = SystemManagerClientInterface(
Entropy,
MethodsInterface = SystemManagerRepositoryMethodsInterface,
ClientCommandsInterface = SystemManagerRepositoryClientCommands
)
def fake_callback(s):
return s
input_params = [
('password','Password',fake_callback,True)
]
data = Entropy.input_box(
'insert root password',
input_params,
cancel_button = True
)
if isinstance(data,dict):
cli_srv.setup_connection('localhost', 1027, 'root', data['password'])
print cli_srv.get_available_client_commands()
#print cli_srv.Methods.compile_atom('sys-libs/zlib')
#st, queue = cli_srv.Methods.get_queue()
#if st: print queue['processing']
@@ -1,530 +0,0 @@
# -*- coding: utf-8 -*-
"""
@author: Fabio Erculiani <lxnay@sabayon.org>
@contact: lxnay@sabayon.org
@copyright: Fabio Erculiani
@license: GPL-2
B{Entropy Client Services Base Commands}.
"""
from entropy.const import etpConst
from entropy.services.exceptions import EntropyServicesError
import entropy.dump
import entropy.tools
from entropy.client.services.ugc.commands import Base
class Client(Base):
def __init__(self, *args, **kwargs):
Base.__init__(self, *args, **kwargs)
def service_login(self, username, password, session_id):
cmd = "%s %s %s %s %s" % (
session_id,
'login',
username,
'plain',
password,
)
return self.do_generic_handler(cmd, session_id)
def get_queue(self, session_id, extended):
cmd = "%s %s %s" % (
session_id,
'systemsrv:get_queue',
extended,
)
return self.do_generic_handler(cmd, session_id)
def get_queue_item_by_id(self, session_id, queue_id):
cmd = "%s %s %d" % (
session_id,
'systemsrv:get_queue_item_by_id',
queue_id,
)
return self.do_generic_handler(cmd, session_id)
def get_queue_id_stdout(self, session_id, queue_id, last_bytes):
cmd = "%s %s %d %d" % (
session_id,
'systemsrv:get_queue_id_stdout',
queue_id,
last_bytes,
)
# enable zlib compression
try:
compression = self._set_gzip_compression(session_id, True)
except EntropyServicesError:
return False, 'connection error'
rc = self.do_generic_handler(cmd, session_id, compression = compression)
# disable compression
try:
compression = self._set_gzip_compression(session_id, False)
except EntropyServicesError:
return False, 'connection error'
return rc
def get_queue_id_result(self, session_id, queue_id):
cmd = "%s %s %d" % (
session_id,
'systemsrv:get_queue_id_result',
queue_id,
)
# enable zlib compression
try:
compression = self._set_gzip_compression(session_id, True)
except EntropyServicesError:
return False, 'connection error'
rc = self.do_generic_handler(cmd, session_id, compression = compression)
# disable compression
try:
compression = self._set_gzip_compression(session_id, False)
except EntropyServicesError:
return False, 'connection error'
return rc
def remove_queue_ids(self, session_id, queue_ids):
cmd = "%s %s %s" % (
session_id,
'systemsrv:remove_queue_ids',
' '.join([str(x) for x in queue_ids]),
)
return self.do_generic_handler(cmd, session_id)
def pause_queue(self, session_id, do_pause):
cmd = "%s %s %s" % (
session_id,
'systemsrv:pause_queue',
do_pause,
)
return self.do_generic_handler(cmd, session_id)
def kill_processing_queue_id(self, session_id, queue_id):
cmd = "%s %s %s" % (
session_id,
'systemsrv:kill_processing_queue_id',
queue_id,
)
return self.do_generic_handler(cmd, session_id)
def swap_items_in_queue(self, session_id, queue_id1, queue_id2):
cmd = "%s %s %d %d" % (
session_id,
'systemsrv:swap_items_in_queue',
queue_id1,
queue_id2,
)
return self.do_generic_handler(cmd, session_id)
def get_pinboard_data(self, session_id):
cmd = "%s %s" % (
session_id,
'systemsrv:get_pinboard_data',
)
return self.do_generic_handler(cmd, session_id)
def add_to_pinboard(self, session_id, note, extended_text):
mydict = {
'note': note,
'extended_text': extended_text,
}
xml_string = entropy.tools.xml_from_dict(mydict)
cmd = "%s %s %s" % (
session_id,
'systemsrv:add_to_pinboard',
xml_string,
)
return self.do_generic_handler(cmd, session_id)
def remove_from_pinboard(self, session_id, pinboard_ids):
cmd = "%s %s %s" % (
session_id,
'systemsrv:remove_from_pinboard',
' '.join([str(x) for x in pinboard_ids]),
)
return self.do_generic_handler(cmd, session_id)
def set_pinboard_items_done(self, session_id, pinboard_ids, status):
cmd = "%s %s %s %s" % (
session_id,
'systemsrv:set_pinboard_items_done',
' '.join([str(x) for x in pinboard_ids]),
status,
)
return self.do_generic_handler(cmd, session_id)
def write_to_running_command_pipe(self, session_id, queue_id, write_to_stdout, txt):
cmd = "%s %s %s %s %s" % (
session_id,
'systemsrv:write_to_running_command_pipe',
queue_id,
write_to_stdout,
txt,
)
return self.do_generic_handler(cmd, session_id)
class Repository(Client):
def sync_spm(self, session_id):
cmd = "%s %s" % (
session_id,
'srvrepo:sync_spm',
)
return self.do_generic_handler(cmd, session_id)
def compile_atoms(self, session_id, atoms, pretend = False, oneshot = False,
verbose = False, nocolor = True, fetchonly = False, buildonly = False,
nodeps = False, custom_use = '', ldflags = '', cflags = ''):
s_pretend = "0"
s_oneshot = "0"
s_verbose = "0"
s_nocolor = "0"
s_fetchonly = "0"
s_buildonly = "0"
s_nodeps = "0"
if pretend:
s_pretend = "1"
if oneshot:
s_oneshot = "1"
if verbose:
s_verbose = "1"
if nocolor:
s_nocolor = "1"
if fetchonly:
s_fetchonly = "1"
if buildonly:
s_buildonly = "1"
if nodeps:
s_nodeps = "1"
mydict = {
'atoms': ' '.join(atoms),
'pretend': s_pretend,
'oneshot': s_oneshot,
'verbose': s_verbose,
'nocolor': s_nocolor,
'fetchonly': s_fetchonly,
'buildonly': s_buildonly,
'nodeps': s_nodeps,
'custom_use': custom_use,
'ldflags': ldflags,
'cflags': cflags,
}
xml_string = entropy.tools.xml_from_dict(mydict)
cmd = "%s %s %s" % (
session_id,
'srvrepo:compile_atoms',
xml_string,
)
return self.do_generic_handler(cmd, session_id)
def spm_remove_atoms(self, session_id, atoms, pretend = False, verbose = False, nocolor = True):
s_pretend = "0"
s_verbose = "0"
s_nocolor = "0"
if pretend:
s_pretend = "1"
if verbose:
s_verbose = "1"
if nocolor:
s_nocolor = "1"
mydict = {
'atoms': ' '.join(atoms),
'pretend': s_pretend,
'verbose': s_verbose,
'nocolor': s_nocolor,
}
xml_string = entropy.tools.xml_from_dict(mydict)
cmd = "%s %s %s" % (
session_id,
'srvrepo:spm_remove_atoms',
xml_string,
)
return self.do_generic_handler(cmd, session_id)
def get_spm_categories_updates(self, session_id, categories):
cmd = "%s %s %s" % (
session_id,
'srvrepo:get_spm_categories_updates',
' '.join(categories),
)
return self.do_generic_handler(cmd, session_id)
def get_spm_categories_installed(self, session_id, categories):
cmd = "%s %s %s" % (
session_id,
'srvrepo:get_spm_categories_installed',
' '.join(categories),
)
return self.do_generic_handler(cmd, session_id)
def enable_uses_for_atoms(self, session_id, atoms, useflags):
mydict = {
'atoms': ' '.join(atoms),
'useflags': ' '.join(useflags),
}
xml_string = entropy.tools.xml_from_dict(mydict)
cmd = "%s %s %s" % (
session_id,
'srvrepo:enable_uses_for_atoms',
xml_string,
)
return self.do_generic_handler(cmd, session_id)
def disable_uses_for_atoms(self, session_id, atoms, useflags):
mydict = {
'atoms': ' '.join(atoms),
'useflags': ' '.join(useflags),
}
xml_string = entropy.tools.xml_from_dict(mydict)
cmd = "%s %s %s" % (
session_id,
'srvrepo:disable_uses_for_atoms',
xml_string,
)
return self.do_generic_handler(cmd, session_id)
def get_spm_atoms_info(self, session_id, atoms):
cmd = "%s %s %s" % (
session_id,
'srvrepo:get_spm_atoms_info',
' '.join(atoms),
)
return self.do_generic_handler(cmd, session_id)
def run_spm_info(self, session_id):
cmd = "%s %s" % (
session_id,
'srvrepo:run_spm_info',
)
return self.do_generic_handler(cmd, session_id)
def run_custom_shell_command(self, session_id, command):
cmd = "%s %s %s" % (
session_id,
'srvrepo:run_custom_shell_command',
command,
)
return self.do_generic_handler(cmd, session_id)
def get_spm_glsa_data(self, session_id, list_type):
cmd = "%s %s %s" % (
session_id,
'srvrepo:get_spm_glsa_data',
list_type,
)
return self.do_generic_handler(cmd, session_id)
def get_available_repositories(self, session_id):
cmd = "%s %s" % (
session_id,
'srvrepo:get_available_repositories',
)
return self.do_generic_handler(cmd, session_id)
def set_default_repository(self, session_id, repoid):
cmd = "%s %s %s" % (
session_id,
'srvrepo:set_default_repository',
repoid,
)
return self.do_generic_handler(cmd, session_id)
def get_available_entropy_packages(self, session_id, repoid):
cmd = "%s %s %s" % (
session_id,
'srvrepo:get_available_entropy_packages',
repoid,
)
return self.do_generic_handler(cmd, session_id)
def get_entropy_idpackage_information(self, session_id, idpackage, repoid):
cmd = "%s %s %d %s" % (
session_id,
'srvrepo:get_entropy_idpackage_information',
idpackage,
repoid,
)
return self.do_generic_handler(cmd, session_id)
def remove_entropy_packages(self, session_id, matched_atoms):
cmd = "%s %s %s" % (
session_id,
'srvrepo:remove_entropy_packages',
','.join(["%s%s%s" % (str(x[0]), etpConst['entropyslotprefix'],
str(x[1]),) for x in matched_atoms]), # 1:repoid,2:repoid
)
return self.do_generic_handler(cmd, session_id)
def search_entropy_packages(self, session_id, search_type, search_string, repoid):
cmd = "%s %s %s %s %s" % (
session_id,
'srvrepo:search_entropy_packages',
repoid,
search_type,
search_string,
)
return self.do_generic_handler(cmd, session_id)
def move_entropy_packages_to_repository(self, session_id, idpackages, from_repo, to_repo, do_copy):
cmd = "%s %s %s %s %s %s" % (
session_id,
'srvrepo:move_entropy_packages_to_repository',
from_repo,
to_repo,
do_copy,
' '.join([str(x) for x in idpackages]),
)
return self.do_generic_handler(cmd, session_id)
def scan_entropy_packages_database_changes(self, session_id):
cmd = "%s %s" % (
session_id,
'srvrepo:scan_entropy_packages_database_changes',
)
return self.do_generic_handler(cmd, session_id)
def run_entropy_database_updates(self, session_id, to_add, to_remove, to_inject):
cmd = "%s %s %s %s %s" % (
session_id,
'srvrepo:run_entropy_database_updates',
','.join(["%s:%s:%s" % (str(x[0]), str(x[1]), str(x[2]),) for x in to_add]),
','.join(["%s:%s" % (str(x[0]), str(x[1]),) for x in to_remove]),
','.join(["%s:%s" % (str(x[0]), str(x[1]),) for x in to_inject]),
)
return self.do_generic_handler(cmd, session_id)
def run_entropy_dependency_test(self, session_id):
cmd = "%s %s" % (
session_id,
'srvrepo:run_entropy_dependency_test',
)
return self.do_generic_handler(cmd, session_id)
def run_entropy_library_test(self, session_id):
cmd = "%s %s" % (
session_id,
'srvrepo:run_entropy_library_test',
)
return self.do_generic_handler(cmd, session_id)
def run_entropy_treeupdates(self, session_id, repoid):
cmd = "%s %s %s" % (
session_id,
'srvrepo:run_entropy_treeupdates',
repoid,
)
return self.do_generic_handler(cmd, session_id)
def scan_entropy_mirror_updates(self, session_id, repositories):
cmd = "%s %s %s" % (
session_id,
'srvrepo:scan_entropy_mirror_updates',
' '.join(repositories),
)
return self.do_generic_handler(cmd, session_id)
def run_entropy_mirror_updates(self, session_id, repository_data):
serialized_string = entropy.dump.serialize_string(repository_data)
cmd = "%s %s %s" % (
session_id,
'srvrepo:run_entropy_mirror_updates',
serialized_string,
)
return self.do_generic_handler(cmd, session_id)
def run_entropy_checksum_test(self, session_id, repoid, mode):
cmd = "%s %s %s %s" % (
session_id,
'srvrepo:run_entropy_checksum_test',
repoid,
mode,
)
return self.do_generic_handler(cmd, session_id)
def get_notice_board(self, session_id, repoid):
cmd = "%s %s %s" % (
session_id,
'srvrepo:get_notice_board',
repoid,
)
return self.do_generic_handler(cmd, session_id)
def remove_notice_board_entries(self, session_id, repoid, entry_ids):
cmd = "%s %s %s %s" % (
session_id,
'srvrepo:remove_notice_board_entries',
repoid,
' '.join([str(x) for x in entry_ids]),
)
return self.do_generic_handler(cmd, session_id)
def add_notice_board_entry(self, session_id, repoid, title, notice_text, link):
mydict = {
'repoid': repoid,
'title': title,
'notice_text': notice_text,
'link': link,
}
xml_string = entropy.tools.xml_from_dict(mydict)
cmd = "%s %s %s" % (
session_id,
'srvrepo:add_notice_board_entry',
xml_string,
)
return self.do_generic_handler(cmd, session_id)
@@ -1,283 +0,0 @@
# -*- coding: utf-8 -*-
"""
@author: Fabio Erculiani <lxnay@sabayon.org>
@contact: lxnay@sabayon.org
@copyright: Fabio Erculiani
@license: GPL-2
B{Entropy Client Services Base Interface}.
"""
import time
from entropy.const import const_isstring, etpUi
from entropy.services.exceptions import EntropyServicesError
from entropy.i18n import _
from entropy.misc import TimeScheduled
class Client:
ssl_connection = True
def __init__(self, OutputInterface, MethodsInterface = None,
ClientCommandsInterface = None, quiet = True, show_progress = False,
do_cache_connection = False, do_cache_session = False,
socket_timeout = 120.0):
if not hasattr(OutputInterface, 'output'):
mytxt = _("OutputInterface does not have an output method")
raise AttributeError("%s, (! %s !)" % (
OutputInterface, mytxt,))
elif not hasattr(OutputInterface.output, '__call__'):
mytxt = _("OutputInterface does not have an output method")
raise AttributeError("%s, (! %s !)" % (
OutputInterface, mytxt,))
from entropy.client.services.system.commands import Client as ClientCommands
if not issubclass(ClientCommandsInterface, ClientCommands):
mytxt = _("A valid entropy.client.services.system.commands.Client class/subclass is needed")
raise AttributeError(mytxt)
from entropy.client.services.system.methods import BaseMixin
if not issubclass(MethodsInterface, BaseMixin):
mytxt = _("A valid entropy.client.services.system.methods.BaseMixin class/subclass is needed")
raise AttributeError(mytxt)
self.ClientCommandsInterface = ClientCommandsInterface
import socket, struct
self.socket, self.struct = socket, struct
from datetime import datetime
self.datetime = datetime
import threading
self.threading = threading
self.Output = OutputInterface
self.hostname = None
self.hostport = None
self.username = None
self.password = None
if quiet and etpUi['debug']: # enforce quiet value if debug is enabled
quiet = False
self.quiet = quiet
self.socket_timeout = socket_timeout
self.do_cache_connection = do_cache_connection
self.show_progress = show_progress
self.ClientCommandsInterface = ClientCommandsInterface
self.Methods = MethodsInterface(self)
self.session_cache = {}
self.SessionCacheLock = self.threading.Lock()
self.connection_cache = {}
self.CacheLock = self.threading.Lock()
self.shutdown = False
self.connection_killer = None
# NOTE actually session cache doesn't work when the connection is closed and re-opened
# when the server is spawning requests under a child process (fork_requests = True)
# this should be fixed by pushing the cache to disk but triggers a possible security issue
# since sessions and their password are stored in memory and kept alive there until those
# expires
self.do_cache_session = do_cache_session
if self.do_cache_connection:
self.connection_killer = TimeScheduled(2,
self.connection_killer_handler)
self.connection_killer.start()
def __del__(self):
if hasattr(self, 'shutdown'):
self.shutdown = True
if hasattr(self, 'connection_killer'):
if self.connection_killer != None:
self.connection_killer.kill()
def _validate_credentials(self):
if not const_isstring(self.hostname):
raise AttributeError("hostname: %s. %s" % (
_('not a string'), _('Please use setup_connection() properly'),))
if not const_isstring(self.username):
raise AttributeError("username: %s. %s" % (
_('not a string'), _('Please use setup_connection() properly'),))
if not const_isstring(self.password):
raise AttributeError("password: %s. %s" % (
_('not a string'), _('Please use setup_connection() properly'),))
if not isinstance(self.hostport, int):
raise AttributeError("port: %s. %s" % (
_('not an int'), _('Please use setup_connection() properly'),))
if not isinstance(self.ssl_connection, bool):
raise AttributeError("ssl_connection: %s. %s" % (
_('not a bool'), _('Please use setup_connection() properly'),))
def get_session_cache(self, cmd_tuple):
if self.do_cache_session:
with self.SessionCacheLock:
return self.session_cache.get(cmd_tuple)
def set_session_cache(self, cmd_tuple, session_id):
if self.do_cache_session:
with self.SessionCacheLock:
self.session_cache[cmd_tuple] = session_id
def remove_session_cache(self, cmd_tuple):
if self.do_cache_session:
with self.SessionCacheLock:
del self.session_cache[cmd_tuple]
def get_connection_cache_key(self):
return hash((self.hostname, self.hostport, self.username, self.password, self.ssl_connection,))
def get_connection_cache(self):
if self.do_cache_connection:
key = self.get_connection_cache_key()
srv = self.connection_cache.get(key)
# NOTE: if you enable cache connection, you should also
# consider to clear the socket buffer
# srv.sock_conn
# srv.real_sock_conn
return srv
def cache_connection(self, srv):
if self.do_cache_connection:
key = self.get_connection_cache_key()
self.connection_cache[key] = {
'conn': srv,
'ts': self.get_ts(),
}
def update_connection_ts(self):
if self.do_cache_connection:
key = self.get_connection_cache_key()
if key not in self.connection_cache:
return
self.connection_cache[key]['ts'] = self.get_ts()
def kill_all_connections(self):
if self.do_cache_connection:
self.CacheLock.acquire()
try:
keys = list(self.connection_cache.keys())
for key in keys:
data = self.connection_cache.pop(key)
data['conn'].disconnect()
finally:
self.CacheLock.release()
def connection_killer_handler(self):
if not self.do_cache_connection:
return
if self.shutdown:
return
if not self.connection_cache:
return
keys = list(self.connection_cache.keys())
for key in keys:
curr_ts = self.get_ts()
ts = self.connection_cache[key]['ts']
delta = curr_ts - ts
if delta.seconds < 60:
continue
self.CacheLock.acquire()
try:
data = self.connection_cache.pop(key)
finally:
self.CacheLock.release()
srv = data['conn']
srv.disconnect()
def get_ts(self):
return self.datetime.fromtimestamp(time.time())
def setup_connection(self, hostname, port, username, password, ssl):
self.hostname = hostname
self.hostport = port
self.username = username
self.password = password
self.ssl_connection = ssl
self._validate_credentials()
def connect_to_service(self, timeout = None):
self._validate_credentials()
args = [self.Output, self.ClientCommandsInterface]
kwargs = {
'ssl': self.ssl_connection,
'quiet': self.quiet,
'show_progress': self.show_progress
}
if timeout is None:
kwargs['socket_timeout'] = self.socket_timeout
else:
kwargs['socket_timeout'] = timeout
from entropy.services.ugc.interfaces import Client
srv = Client(*args, **kwargs)
srv.connect(self.hostname, self.hostport)
return srv
def get_service_connection(self, timeout = None):
try:
srv = self.connect_to_service(timeout = timeout)
except EntropyServicesError:
return None
return srv
def logout(self, srv, session_id):
self._validate_credentials()
return srv.CmdInterface.service_logout(self.username, session_id)
def login(self, srv, session_id):
self._validate_credentials()
return srv.CmdInterface.service_login(self.username, self.password, session_id)
# eval(func) must have session as first param
def do_cmd(self, login_required, func, args, kwargs):
with self.CacheLock:
srv = self.get_connection_cache()
if srv is None:
srv = self.get_service_connection(timeout = self.socket_timeout)
if srv != None:
self.cache_connection(srv)
else:
srv = srv['conn']
if srv is None:
return False, 'no connection'
cmd_tuple = (login_required, func,)
new_session = False
session = self.get_session_cache(cmd_tuple)
if session is None:
new_session = True
session = srv.open_session()
if session is None:
return False, 'no session'
else:
if not srv.is_session_alive(session):
new_session = True
session = srv.open_session()
if session is None:
return False, 'no session'
self.set_session_cache(cmd_tuple, session)
self.update_connection_ts()
args.insert(0, session)
if login_required and new_session:
logged, error = self.login(srv, session)
if not logged:
srv.close_session(session)
self.remove_session_cache(cmd_tuple)
if not self.do_cache_connection:
srv.disconnect()
return False, error
cmd_func = getattr(srv.CmdInterface, func)
rslt = cmd_func(*args, **kwargs)
if not self.do_cache_session:
if login_required:
self.logout(srv, session)
srv.close_session(session)
if not self.do_cache_connection:
srv.disconnect()
return rslt
def get_available_client_commands(self):
return self.Methods.available_commands.copy()
@@ -1,520 +0,0 @@
# -*- coding: utf-8 -*-
"""
@author: Fabio Erculiani <lxnay@sabayon.org>
@contact: lxnay@sabayon.org
@copyright: Fabio Erculiani
@license: GPL-2
B{Entropy Client Services Base Mixin Interfaces}.
"""
from entropy.const import const_get_stringtype
from entropy.i18n import _
class BaseMixin:
def __init__(self, SystemManagerClientInstance):
self.Manager = SystemManagerClientInstance
str_type = const_get_stringtype()
self.available_commands = {
'get_available_commands': {
'desc': _("Get a list of remotely available commands"),
'params': [],
'call': self.get_available_commands,
'private': True,
},
'get_queue': {
'desc': _("Get current queue content"),
'params': [
('extended', bool, _('Extended results'), False,)
],
'call': self.get_queue,
'private': True,
},
'get_queue_item_by_id': {
'desc': _("Get queue item using its queue unique identifier"),
'params': [('queue_id', int, _('Queue Identifier'), True,)],
'call': self.get_queue_item_by_id,
'private': True,
},
'get_queue_id_stdout': {
'desc': _("Get queue stdout/stderr using its queue unique identifier"),
'params': [('queue_id', int, _('Queue Identifier'), True,)],
'call': self.get_queue_id_stdout,
'private': True,
},
'remove_queue_ids': {
'desc': _("Remove queued commands using their queue unique identifiers"),
'params': [('queue_ids', list, _('Queue Identifiers'), True,)],
'call': self.remove_queue_ids,
'private': True,
},
'pause_queue': {
'desc': _("Toggle queue pause (True/False)"),
'params': [('do_pause', bool, _('Pause or not'), True,)],
'call': self.pause_queue,
'private': True,
},
'kill_processing_queue_id': {
'desc': _("Kill a running process through its queue id"),
'params': [('queue_id', int, _('Queue Identifier'), True,)],
'call': self.kill_processing_queue_id,
'private': True,
},
'swap_items_in_queue': {
'desc': _("Swap items in queue using their queue ids"),
'params': [
('queue_id1', int, _('Queue Identifier'), True,),
('queue_id2', int, _('Queue Identifier'), True,)
],
'call': self.swap_items_in_queue,
'private': True,
},
'get_pinboard_data': {
'desc': _("Get pinboard content"),
'params': [],
'call': self.get_pinboard_data,
'private': True,
},
'add_to_pinboard': {
'desc': _("Add item to pinboard"),
'params': [
('note', str_type, _('Note'), True,),
('extended_text', str_type, _('Extended text'), True,)
],
'call': self.add_to_pinboard,
'private': True,
},
'remove_from_pinboard': {
'desc': _("Remove item from pinboard"),
'params': [('pinboard_ids', list, _('Pinboard identifiers'), True,)],
'call': self.remove_from_pinboard,
'private': True,
},
'set_pinboard_items_done': {
'desc': _("Set pinboard items status (done/not done)"),
'params': [
('pinboard_ids', list, _('Pinboard identifiers'), True,),
('done_status', bool, _('Done status'), True,),
],
'call': self.set_pinboard_items_done,
'private': True,
},
'write_to_running_command_pipe': {
'desc': _("Write to a remote running command stdin"),
'params': [
('queue_id', int, _('Queue Identifier'), True,),
('write_to_stdout', bool, _('Write to stdout?'), True,),
('txt', str_type, _('Text'), True,),
],
'call': self.write_to_running_command_pipe,
'private': True,
},
}
def get_available_commands(self):
return self.Manager.do_cmd(False, "available_commands", [], {})
def get_queue(self, extended = False):
return self.Manager.do_cmd(True, "get_queue", [extended], {})
def get_queue_item_by_id(self, queue_id):
return self.Manager.do_cmd(True, "get_queue_item_by_id", [queue_id], {})
def get_queue_id_stdout(self, queue_id, last_bytes = 0):
return self.Manager.do_cmd(True, "get_queue_id_stdout", [queue_id, last_bytes], {})
def get_queue_id_result(self, queue_id):
return self.Manager.do_cmd(True, "get_queue_id_result", [queue_id], {})
def remove_queue_ids(self, queue_ids):
return self.Manager.do_cmd(True, "remove_queue_ids", [queue_ids], {})
def pause_queue(self, do_queue):
return self.Manager.do_cmd(True, "pause_queue", [do_queue], {})
def kill_processing_queue_id(self, queue_id):
return self.Manager.do_cmd(True, "kill_processing_queue_id", [queue_id], {})
def swap_items_in_queue(self, queue_id1, queue_id2):
return self.Manager.do_cmd(True, "swap_items_in_queue", [queue_id1, queue_id2], {})
def get_pinboard_data(self):
return self.Manager.do_cmd(True, "get_pinboard_data", [], {})
def add_to_pinboard(self, note, extended_text):
return self.Manager.do_cmd(True, "add_to_pinboard", [note, extended_text], {})
def remove_from_pinboard(self, pinboard_ids):
return self.Manager.do_cmd(True, "remove_from_pinboard", [pinboard_ids], {})
def set_pinboard_items_done(self, pinboard_ids, done_status):
return self.Manager.do_cmd(True, "set_pinboard_items_done", [pinboard_ids, done_status], {})
def write_to_running_command_pipe(self, queue_id, write_to_stdout, txt):
return self.Manager.do_cmd(True, "write_to_running_command_pipe", [queue_id, write_to_stdout, txt], {})
class Repository(BaseMixin):
def __init__(self, *args, **kwargs):
BaseMixin.__init__(self, *args, **kwargs)
str_type = const_get_stringtype()
self.available_commands.update({
'sync_spm': {
'desc': _("Update Spm Repository (emerge --sync)"),
'params': [],
'call': self.sync_spm,
'private': False,
},
'compile_atoms': {
'desc': _("Compile specified atoms with specified parameters"),
'params': [
('atoms', list, _('Atoms'), True,),
('pretend', bool, _('Pretend'), False,),
('oneshot', bool, _('Oneshot'), False,),
('verbose', bool, _('Verbose'), False,),
('nocolor', bool, _('No color'), False,),
('fetchonly', bool, _('Fetch only'), False,),
('buildonly', bool, _('Build only'), False,),
('nodeps', bool, _('No dependencies'), False,),
('custom_use', str_type, _('Custom USE'), False,),
('ldflags', str_type, _('Custom LDFLAGS'), False,),
('cflags', str_type, _('Custom CFLAGS'), False,),
],
'call': self.compile_atoms,
'private': False,
},
'spm_remove_atoms': {
'desc': _("Remove specified atoms with specified parameters"),
'params': [
('atoms', list, _('Atoms'), True,),
('pretend', bool, _('Pretend'), False,),
('verbose', bool, _('Verbose'), False,),
('nocolor', bool, _('No color'), False,),
],
'call': self.spm_remove_atoms,
'private': False,
},
'get_spm_categories_updates': {
'desc': _("Get SPM updates for the specified categories"),
'params': [('categories', list, _('Categories'), True,)],
'call': self.get_spm_categories_updates,
'private': False,
},
'get_spm_categories_installed': {
'desc': _("Get SPM installed packages for the specified categories"),
'params': [('categories', list, _('Categories'), True,)],
'call': self.get_spm_categories_installed,
'private': False,
},
'enable_uses_for_atoms': {
'desc': _("Enable USE flags for the specified atoms"),
'params': [
('atoms', list, _('Atoms'), True,),
('useflags', list, _('USE flags'), True,)
],
'call': self.enable_uses_for_atoms,
'private': False,
},
'disable_uses_for_atoms': {
'desc': _("Disable USE flags for the specified atoms"),
'params': [
('atoms', list, _('Atoms'), True,),
('useflags', list, _('USE flags'), True,)
],
'call': self.disable_uses_for_atoms,
'private': False,
},
'get_spm_atoms_info': {
'desc': _("Get info for the specified atoms"),
'params': [('atoms', list, _('Atoms'), True,)],
'call': self.get_spm_atoms_info,
'private': False,
},
'run_spm_info': {
'desc': _("Run SPM info command"),
'params': [],
'call': self.run_spm_info,
'private': False,
},
'run_custom_shell_command': {
'desc': _("Run custom shell command"),
'params': [
('command', str_type, _('Command'), True,)
],
'call': self.run_custom_shell_command,
'private': False,
},
'get_spm_glsa_data': {
'desc': _("Get Spm security updates information"),
'params': [
('list_type', str_type, _('List type (affected,new,all)'), True,)
],
'call': self.get_spm_glsa_data,
'private': False,
},
'get_available_repositories': {
'desc': _("Get information about available Entropy repositories"),
'params': [],
'call': self.get_available_repositories,
'private': False,
},
'set_default_repository': {
'desc': _("Set default Entropy Server repository"),
'params': [
('repoid', str_type, _('Repository Identifier'), True,)
],
'call': self.set_default_repository,
'private': False,
},
'get_available_entropy_packages': {
'desc': _("Get available packages inside the specified repository"),
'params': [
('repoid', str_type, _('Repository Identifier'), True,)
],
'call': self.get_available_entropy_packages,
'private': False,
},
'get_entropy_idpackage_information': {
'desc': _("Get idpackage metadata using its idpackage in the specified repository"),
'params': [
('idpackage', int, _('Package Identifier'), True,),
('repoid', str_type, _('Repository Identifier'), True,)
],
'call': self.get_entropy_idpackage_information,
'private': False,
},
'remove_entropy_packages': {
'desc': _("Remove the specified Entropy package matches (idpackage,repoid)"),
'params': [
('matched_atoms', list, _('Matched atoms'), True,)
],
'call': self.remove_entropy_packages,
'private': False,
},
'search_entropy_packages': {
'desc': _("Search Entropy packages using a defined set of search types in the specified repository"),
'params': [
('search_type', str_type, _('Search type'), True,),
('search_string', str_type, _('Search string'), True,),
('repoid', str_type, _('Repository Identifier'), True,)
],
'call': self.search_entropy_packages,
'private': False,
},
'move_entropy_packages_to_repository': {
'desc': _("Move or copy a package from a repository to another"),
'params': [
('idpackages', list, _('Package identifiers'), True,),
('from_repo', str_type, _('From repository'), True,),
('to_repo', str_type, _('To repository'), True,),
('do_copy', bool, _('Copy instead of move?'), False,)
],
'call': self.search_entropy_packages,
'private': False,
},
'scan_entropy_packages_database_changes': {
'desc': _("Scan Spm package changes and retrieve a list of action that should be run on the repositories"),
'params': [],
'call': self.scan_entropy_packages_database_changes,
'private': False,
},
'run_entropy_database_updates': {
'desc': _("Run Entropy database updates"),
'params': [
('to_add', list, _('Matches to add from Spm'), True,),
('to_remove', list, _('Matches to remove from repository database'), True,),
('to_inject', list, _('Matches to inject on repository database'), True,),
],
'call': self.run_entropy_database_updates,
'private': False,
},
'run_entropy_dependency_test': {
'desc': _("Run Entropy dependency test"),
'params': [],
'call': self.run_entropy_dependency_test,
'private': False,
},
'run_entropy_library_test': {
'desc': _("Run Entropy library test"),
'params': [],
'call': self.run_entropy_library_test,
'private': False,
},
'run_entropy_treeupdates': {
'desc': _("Run Entropy tree updates"),
'params': [
('repoid', str_type, _('Repository Identifier'), True,),
],
'call': self.run_entropy_treeupdates,
'private': False,
},
'scan_entropy_mirror_updates': {
'desc': _("Scan for Mirror updates and retrieve a list of action that should be run"),
'params': [
('repositories', list, _('list of repository identifiers'), True,),
],
'call': self.scan_entropy_mirror_updates,
'private': False,
},
'run_entropy_mirror_updates': {
'desc': _("Run Mirror updates for the provided repositories and its data"),
'params': [
('repository_data', dict, _('composed repository data'), True,),
],
'call': self.run_entropy_mirror_updates,
'private': False,
},
'run_entropy_checksum_test': {
'desc': _("Run Entropy packages digest verification test"),
'params': [
('repoid', str_type, _('Repository Identifier'), True,),
('mode', str_type, _('Check mode'), False,),
],
'call': self.run_entropy_mirror_updates,
'private': False,
},
'get_notice_board': {
'desc': _("Get repository notice board"),
'params': [('repoid', str_type, _('Repository Identifier'), True,),],
'call': self.get_notice_board,
'private': False,
},
'remove_notice_board_entries': {
'desc': _("Remove notice board entry"),
'params': [
('repoid', str_type, _('Repository Identifier'), True,),
('entry_ids', list, _('Entry Identifiers'), True,),
],
'call': self.remove_notice_board_entries,
'private': False,
},
'add_notice_board_entry': {
'desc': _("Add notice board entry"),
'params': [
('repoid', str_type, _('Repository Identifier'), True,),
('title', str_type, _('Title'), True,),
('notice_text', str_type, _('Text'), True,),
('link', str_type, _('Notice link'), True,),
],
'call': self.add_notice_board_entry,
'private': False,
},
})
def sync_spm(self):
return self.Manager.do_cmd(True, "sync_spm", [], {})
def compile_atoms(self, atoms, pretend = False, oneshot = False,
verbose = True, nocolor = True, fetchonly = False, buildonly = False,
nodeps = False, custom_use = '', ldflags = '', cflags = ''):
return self.Manager.do_cmd(
True,
"compile_atoms",
[atoms],
{
'pretend': pretend,
'oneshot': oneshot,
'verbose': verbose,
'nocolor': nocolor,
'fetchonly': fetchonly,
'buildonly': buildonly,
'nodeps': nodeps,
'custom_use': custom_use,
'ldflags': ldflags,
'cflags': cflags,
}
)
def spm_remove_atoms(self, atoms, pretend = True, verbose = True, nocolor = True):
return self.Manager.do_cmd(
True,
"spm_remove_atoms",
[atoms],
{
'pretend': pretend,
'verbose': verbose,
'nocolor': nocolor,
}
)
def get_spm_categories_updates(self, categories):
return self.Manager.do_cmd(True, "get_spm_categories_updates", [categories], {})
def get_spm_categories_installed(self, categories):
return self.Manager.do_cmd(True, "get_spm_categories_installed", [categories], {})
def enable_uses_for_atoms(self, atoms, useflags):
return self.Manager.do_cmd(True, "enable_uses_for_atoms", [atoms, useflags], {})
def disable_uses_for_atoms(self, atoms, useflags):
return self.Manager.do_cmd(True, "disable_uses_for_atoms", [atoms, useflags], {})
def get_spm_atoms_info(self, atoms):
return self.Manager.do_cmd(True, "get_spm_atoms_info", [atoms], {})
def run_spm_info(self):
return self.Manager.do_cmd(True, "run_spm_info", [], {})
def run_custom_shell_command(self, command):
return self.Manager.do_cmd(True, "run_custom_shell_command", [command], {})
def get_spm_glsa_data(self, list_type = "affected"):
return self.Manager.do_cmd(True, "get_spm_glsa_data", [list_type], {})
def get_available_repositories(self):
return self.Manager.do_cmd(True, "get_available_repositories", [], {})
def set_default_repository(self, repoid):
return self.Manager.do_cmd(True, "set_default_repository", [repoid], {})
def get_available_entropy_packages(self, repoid):
return self.Manager.do_cmd(True, "get_available_entropy_packages", [repoid], {})
def get_entropy_idpackage_information(self, idpackage, repoid):
return self.Manager.do_cmd(True, "get_entropy_idpackage_information", [idpackage, repoid], {})
def remove_entropy_packages(self, matched_atoms):
return self.Manager.do_cmd(True, "remove_entropy_packages", [matched_atoms], {})
def search_entropy_packages(self, search_type, search_string, repoid):
return self.Manager.do_cmd(True, "search_entropy_packages", [search_type, search_string, repoid], {})
def move_entropy_packages_to_repository(self, idpackages, from_repo, to_repo, do_copy = False):
return self.Manager.do_cmd(True, "move_entropy_packages_to_repository", [idpackages, from_repo, to_repo, do_copy], {})
def scan_entropy_packages_database_changes(self):
return self.Manager.do_cmd(True, "scan_entropy_packages_database_changes", [], {})
def run_entropy_database_updates(self, to_add, to_remove, to_inject):
return self.Manager.do_cmd(True, "run_entropy_database_updates", [to_add, to_remove, to_inject], {})
def run_entropy_dependency_test(self):
return self.Manager.do_cmd(True, "run_entropy_dependency_test", [], {})
def run_entropy_library_test(self):
return self.Manager.do_cmd(True, "run_entropy_library_test", [], {})
def run_entropy_treeupdates(self, repoid):
return self.Manager.do_cmd(True, "run_entropy_treeupdates", [repoid], {})
def scan_entropy_mirror_updates(self, repositories):
return self.Manager.do_cmd(True, "scan_entropy_mirror_updates", [repositories], {})
def run_entropy_mirror_updates(self, repository_data):
return self.Manager.do_cmd(True, "run_entropy_mirror_updates", [repository_data], {})
def run_entropy_checksum_test(self, repoid, mode = "local"):
return self.Manager.do_cmd(True, "run_entropy_checksum_test", [repoid, mode], {})
def get_notice_board(self, repoid):
return self.Manager.do_cmd(True, "get_notice_board", [repoid], {})
def remove_notice_board_entries(self, repoid, entry_ids):
return self.Manager.do_cmd(True, "remove_notice_board_entries", [repoid, entry_ids], {})
def add_notice_board_entry(self, repoid, title, notice_text, link):
return self.Manager.do_cmd(True, "add_notice_board_entry", [repoid, title, notice_text, link], {})
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,547 +0,0 @@
# -*- coding: utf-8 -*-
"""
@author: Fabio Erculiani <lxnay@sabayon.org>
@contact: lxnay@sabayon.org
@copyright: Fabio Erculiani
@license: GPL-2
B{Entropy Services System Management Interface}.
"""
import time
import os
import random
import subprocess
from entropy.services.interfaces import SocketHost
from entropy.const import etpConst, const_setup_perms
from entropy.output import TextInterface
from entropy.misc import ParallelTask
import entropy.dump
import entropy.tools
class TaskExecutor:
def __init__(self, SystemInterface, Entropy):
self.Entropy = Entropy
self.SystemInterface = SystemInterface
self.available_commands = {}
self.task_result = None
def register(self, available_commands):
self.available_commands.update(available_commands)
def execute_task(self, command_data):
import signal
queue_id = command_data['queue_id']
args = command_data['args']
kwargs = command_data['kwargs']
data = self.available_commands.get(command_data['call'])
if data == None:
return False, 'no command'
elif len(args)+1 < data['args']:
return False, 'not enough args'
args.insert(0, queue_id)
self.task_result = None
t = ParallelTask(data['func'], *args, **kwargs)
t.start()
killed = False
while True:
if not t.isAlive():
break
time.sleep(2)
live_item, key = self.SystemInterface.get_item_by_queue_id(queue_id)
if isinstance(live_item, dict) and (key == "processing") and (not killed):
if live_item['kill'] and (live_item['processing_pid'] != None):
os.kill(live_item['processing_pid'], signal.SIGKILL)
killed = True
if killed:
return False, 'killed by user'
return True, t.get_rc()
class Server(SocketHost):
class FakeServiceInterface:
def __init__(self, *args, **kwargs):
pass
class BuiltInSystemManagerExecutorCommands:
def __init__(self, SystemManagerExecutorInstance, *args, **kwargs):
self.SystemManagerExecutor = SystemManagerExecutorInstance
self.available_commands = {
'hello_world': {
'func': self.hello_world,
'args': 0,
}
}
def hello_world(self):
rc = subprocess.call('echo hello world', shell = True)
return True, rc
queue_file = 'system_manager_queue'
pinboard_file = "system_manager_pinboard"
queue_ext_rc_dir = "system_manager_rc"
STDOUT_STORAGE_DIR = os.path.join(etpConst['dumpstoragedir'], 'system_manager_stdout')
def __init__(self, EntropyInterface, do_ssl = False, stdout_logging = True, entropy_interface_kwargs = {}, **kwargs):
self.started = False
self.queue_loaded = False
from entropy.misc import TimeScheduled
self.TimeScheduled = TimeScheduled
import threading
self.threading = threading
from datetime import datetime
self.datetime = datetime
import copy
self.copy = copy
from entropy.services.system.commands import Base
self.setup_stdout_storage_dir()
if 'external_cmd_classes' not in kwargs:
kwargs['external_cmd_classes'] = []
kwargs['external_cmd_classes'].insert(0, Base)
self.Entropy = EntropyInterface(**entropy_interface_kwargs)
self.Text = TextInterface()
self.SystemExecutor = TaskExecutor(self, self.Entropy)
self.ExecutorCommandClasses = [(self.BuiltInSystemManagerExecutorCommands, [], {},)]
self.ExecutorCommandInstances = []
if 'external_executor_cmd_classes' in kwargs:
self.ExecutorCommandClasses += kwargs.pop('external_executor_cmd_classes')
self.handle_executor_command_classes_initialization()
self.QueueProcessor = None
self.QueueLock = self.threading.Lock()
self.PinboardLock = self.threading.Lock()
self.ForkLock = self.threading.Lock()
self.do_ssl = do_ssl
self.PinboardData = {}
self.load_pinboard()
self.done_queue_keys = ['processed', 'errored']
self.removable_queue_keys = ['processed', 'errored', 'queue']
self.processing_queue_keys = ['processing']
self.dict_queue_keys = ['queue', 'processing', 'processed', 'errored']
self.ManagerQueueStdInOut = {}
self.ManagerQueue = {
'queue': {},
'queue_order': [],
'processing': {},
'processing_order': [],
'processed': {},
'processed_order': [],
'errored' : {},
'errored_order': [],
'pause': True
}
self.load_queue()
self.queue_loaded = True
if self.ManagerQueue['processing'] or self.ManagerQueue['processing_order']:
self.ManagerQueue['processing'].clear()
del self.ManagerQueue['processing_order'][:]
self.store_queue()
SocketHost.__init__(
self,
self.FakeServiceInterface,
sock_output = self.Text,
ssl = do_ssl,
**kwargs
)
self.stdout_logging = stdout_logging
# no way, we MUST fork requests, otherwise weird things will happen when more than
# one user is connected
# self.fork_requests = False
self.load_queue_processor()
# here we can put anything that must be loaded before the queue processor execution
self.play_queue()
self.started = True
def __del__(self):
if hasattr(self, 'queue_loaded'):
if self.queue_loaded:
self.store_queue()
def handle_executor_command_classes_initialization(self):
for myclass, args, kwargs in self.ExecutorCommandClasses:
myintf = myclass(self.SystemExecutor, *args, **kwargs)
if hasattr(myintf, 'available_commands'):
self.SystemExecutor.register(myintf.available_commands)
self.ExecutorCommandInstances.append(myintf)
else:
del myintf
def setup_stdout_storage_dir(self):
if os.path.isfile(self.STDOUT_STORAGE_DIR) or os.path.islink(self.STDOUT_STORAGE_DIR):
os.remove(self.STDOUT_STORAGE_DIR)
if not os.path.isdir(self.STDOUT_STORAGE_DIR):
os.makedirs(self.STDOUT_STORAGE_DIR, 0o775)
if etpConst['entropygid'] != None:
const_setup_perms(self.STDOUT_STORAGE_DIR, etpConst['entropygid'])
def load_pinboard(self):
obj = self.get_stored_pinboard()
if isinstance(obj, dict):
self.PinboardData = obj
return True
return False
def get_stored_pinboard(self):
return entropy.dump.loadobj(self.pinboard_file)
def store_pinboard(self):
entropy.dump.dumpobj(self.pinboard_file, self.PinboardData)
def add_to_pinboard(self, note, extended_text):
with self.PinboardLock:
mydata = {
'note': note,
'extended_text': extended_text,
'ts': self.get_ts(),
'done': False,
}
pinboard_id = self.get_pinboard_id()
self.PinboardData[pinboard_id] = mydata
self.store_pinboard()
def remove_from_pinboard(self, pinboard_id):
with self.PinboardLock:
if pinboard_id in self.PinboardData:
self.PinboardData.pop(pinboard_id)
self.store_pinboard()
return True
return False
def set_pinboard_item_status(self, pinboard_id, status):
with self.PinboardLock:
if pinboard_id in self.PinboardData:
self.PinboardData[pinboard_id]['done'] = status
self.store_pinboard()
return True
return False
def get_pinboard_id(self):
numbers = list(self.PinboardData.keys())
if numbers:
number = max(numbers)+1
else:
number = 1
return number
def get_pinboard_data(self):
with self.PinboardLock:
return self.PinboardData.copy()
def load_queue_processor(self):
self.QueueProcessor = self.TimeScheduled(2, self.queue_processor)
self.QueueProcessor.start()
def get_stored_queue(self):
return entropy.dump.loadobj(self.queue_file)
def load_queue(self):
obj = self.get_stored_queue()
if isinstance(obj, dict):
self.ManagerQueue = obj
return True
return False
def store_queue(self):
entropy.dump.dumpobj(self.queue_file, self.ManagerQueue)
def load_queue_ext_rc(self, queue_id):
return entropy.dump.loadobj(os.path.join(self.queue_ext_rc_dir, str(queue_id)))
def store_queue_ext_rc(self, queue_id, rc):
return entropy.dump.dumpobj(os.path.join(self.queue_ext_rc_dir, str(queue_id)), rc)
def remove_queue_ext_rc(self, queue_id):
return entropy.dump.removeobj(os.path.join(self.queue_ext_rc_dir, str(queue_id)))
def get_ts(self):
return self.datetime.fromtimestamp(time.time())
def swap_items_in_queue(self, queue_id1, queue_id2):
self.load_queue()
item1, key1 = self._get_item_by_queue_id(queue_id1)
item2, key2 = self._get_item_by_queue_id(queue_id2)
if key1 != key2:
return False
t_item = item1.copy()
item1.clear()
item1.update(item2)
item2.clear()
item2.update(t_item)
# fix the _order
queue_id1_idx = self.ManagerQueue[key1+"_order"].index(queue_id1)
queue_id2_idx = self.ManagerQueue[key2+"_order"].index(queue_id2)
self.ManagerQueue[key1+"_order"][queue_id1_idx] = queue_id2
self.ManagerQueue[key2+"_order"][queue_id2_idx] = queue_id1
self.store_queue()
return True
def add_to_queue(self, command_name, command_text, user_id, group_id, function, args, kwargs, do_parallel, extended_result, interactive = False):
if function not in self.SystemExecutor.available_commands:
return -1
self.load_queue()
queue_id = self.generate_unique_queue_id()
if interactive:
self.ManagerQueueStdInOut[queue_id] = os.pipe()
myqueue_dict = {
'queue_id': queue_id,
'command_name': command_name,
'command_desc': self.valid_commands[command_name]['desc'],
'command_text': command_text,
'call': function,
'args': self.copy.deepcopy(args),
'kwargs': self.copy.deepcopy(kwargs),
'user_id': user_id,
'group_id': group_id,
'stdout': self.assign_unique_stdout_file(queue_id),
'queue_ts': "%s" % (self.get_ts(),),
'kill': False,
'processing_pid': None,
'do_parallel': do_parallel,
'interactive': False,
}
if extended_result:
myqueue_dict['extended_result'] = None
self.ManagerQueue['queue'][queue_id] = myqueue_dict
self.ManagerQueue['queue_order'].append(queue_id)
self.store_queue()
return queue_id
def remove_from_queue(self, queue_ids):
self.load_queue()
removed = False
for key in self.ManagerQueue:
if key not in self.dict_queue_keys:
continue
for queue_id in queue_ids:
item = None
try:
item = self.ManagerQueue[key].pop(queue_id)
except KeyError:
continue
if item:
self.flush_item(item, queue_id)
if queue_id in self.ManagerQueue[key+"_order"]:
self.ManagerQueue[key+"_order"].remove(queue_id)
removed = True
self.remove_queue_ext_rc(queue_id)
if removed:
self.store_queue()
return removed
def kill_processing_queue_id(self, queue_id):
self.load_queue()
item, key = self._get_item_by_queue_id(queue_id)
if key in self.processing_queue_keys:
item['kill'] = True
self.store_queue()
def pause_queue(self):
self.load_queue()
self.ManagerQueue['pause'] = True
self.store_queue()
def play_queue(self):
self.load_queue()
self.ManagerQueue['pause'] = False
self.store_queue()
def flush_item(self, item, queue_id):
if not isinstance(item, dict):
return False
if 'stdout' in item:
stdout = item['stdout']
if (os.path.isfile(stdout) and os.access(stdout, os.W_OK)):
os.remove(stdout)
if 'interactive' in item:
if item['interactive'] and (queue_id in self.ManagerQueueStdInOut):
stdin, stdout = self.ManagerQueueStdInOut.pop(queue_id)
os.close(stdin)
os.close(stdout)
return True
def assign_unique_stdout_file(self, queue_id):
stdout = os.path.join(self.STDOUT_STORAGE_DIR, "%d.%s" % (queue_id, "stdout",))
if os.path.isfile(stdout):
os.remove(stdout)
count = 0
orig_stdout = stdout
while os.path.lexists(stdout):
count += 1
stdout = "%s.%d" % (orig_stdout, count,)
return stdout
def generate_unique_queue_id(self):
current_ids = set()
for key in self.ManagerQueue:
if not key.endswith("_order"):
continue
current_ids |= set(self.ManagerQueue[key])
while True:
try:
queue_id = abs(hash(os.urandom(1)))
except NotImplementedError:
random.seed()
queue_id = random.randint(1000000000000000000, 9999999999999999999)
if queue_id not in current_ids:
return queue_id
def get_item_by_queue_id(self, queue_id, copy = False):
self.load_queue()
item, key = self._get_item_by_queue_id(queue_id)
if copy: item = self._queue_copy_obj(item)
return item, key
def _get_item_by_queue_id(self, queue_id):
for key in self.dict_queue_keys:
item = self.ManagerQueue[key].get(queue_id)
if item != None:
return item, key
return None, None
def _pop_item_from_queue(self):
try:
if self.ManagerQueue['queue_order']:
queue_id = self.ManagerQueue['queue_order'].pop(0)
return self.ManagerQueue['queue'].pop(queue_id), queue_id
except (IndexError, KeyError,):
entropy.tools.print_traceback()
return None, None
def _queue_copy_obj(self, obj):
if isinstance(obj, (dict, set, frozenset)):
return obj.copy()
elif isinstance(obj, (list, tuple)):
return obj[:]
return obj
def queue_processor(self, fork_data = None):
try:
self._queue_processor(fork_data)
except:
if self.QueueLock.locked() and not fork_data:
self.QueueLock.release()
raise
def _queue_processor(self, fork_data):
# queue processing is stopped until there's a process running
if self.ForkLock.locked():
return
with self.ForkLock:
with self.QueueLock:
if fork_data:
command_data, queue_id = self._queue_copy_obj(fork_data)
else:
self.load_queue()
if self.ManagerQueue['pause']:
return
if not self.ManagerQueue['queue_order']:
return
command_data, queue_id = self._pop_item_from_queue()
if not command_data:
return
command_data = self._queue_copy_obj(command_data)
command_data['processing_ts'] = "%s" % (self.get_ts(),)
self.ManagerQueue['processing'][queue_id] = command_data
self.ManagerQueue['processing_order'].append(queue_id)
self.store_queue()
self.remove_queue_ext_rc(queue_id)
try:
if command_data.get('do_parallel') and not fork_data:
t = ParallelTask(self.queue_processor, fork_data = (command_data, queue_id,))
t.start()
return
done, result = self.SystemExecutor.execute_task(command_data)
except Exception as e:
if self.QueueLock.locked():
self.QueueLock.release()
entropy.tools.print_traceback()
done = False
result = (False, str(e),)
if 'extended_result' in command_data and done:
try:
command_data['result'], extended_result = self._queue_copy_obj(result)
self.store_queue_ext_rc(queue_id, extended_result)
except TypeError:
done = False
command_data['result'] = 'wrong tuple split from queue processor (1)'
self.store_queue_ext_rc(queue_id, None)
else:
command_data['result'] = self._queue_copy_obj(result)
with self.ForkLock:
with self.QueueLock:
self.load_queue()
if not done:
try:
self.ManagerQueue['processing'].pop(queue_id)
except KeyError:
pass
if queue_id in self.ManagerQueue['processing_order']:
self.ManagerQueue['processing_order'].remove(queue_id)
command_data['errored_ts'] = "%s" % (self.get_ts(),)
self.ManagerQueue['errored'][queue_id] = command_data
self.ManagerQueue['errored_order'].append(queue_id)
self.store_queue()
return
try:
done, cmd_result = result
except TypeError:
done = False
command_data['result'] = 'wrong tuple split from queue processor (2)'
if not done:
try:
self.ManagerQueue['processing'].pop(queue_id)
except KeyError:
pass
if queue_id in self.ManagerQueue['processing_order']:
self.ManagerQueue['processing_order'].remove(queue_id)
command_data['errored_ts'] = "%s" % (self.get_ts(),)
self.ManagerQueue['errored'][queue_id] = command_data
self.ManagerQueue['errored_order'].append(queue_id)
self.store_queue()
return
try:
self.ManagerQueue['processing'].pop(queue_id)
except KeyError:
pass
if queue_id in self.ManagerQueue['processing_order']:
self.ManagerQueue['processing_order'].remove(queue_id)
command_data['processed_ts'] = "%s" % (self.get_ts(),)
self.ManagerQueue['processed'][queue_id] = command_data
self.ManagerQueue['processed_order'].append(queue_id)
self.store_queue()
def killall(self):
SocketHost.killall(self)
if self.QueueProcessor != None:
self.QueueProcessor.kill()
@@ -1,277 +0,0 @@
# -*- coding: utf-8 -*-
import sys
sys.path.insert(0, '../../')
sys.path.insert(0, '../../../sulfur/src')
import os
if os.getuid() != 0:
raise SystemError("run this as root")
import signal
import unittest
import time
import socket
from entropy.const import etpUi, etpConst
from entropy.tools import print_traceback
from entropy.services.skel import SocketAuthenticator
from entropy.services.interfaces import SocketHost
from sulfur.dialogs import RepositoryManagerMenu
class FakeAuthenticator(SocketHost.BasicPamAuthenticator):
"""
This class always returns valid login credentials
"""
valid_auth_types = [ "plain", "shadow", "md5" ]
def __get_user_data(self, user):
import pwd
try:
udata = pwd.getpwnam(user)
except KeyError:
return None
return udata
def docmd_login(self, arguments):
if not arguments or (len(arguments) != 3):
return False, None, None, 'wrong arguments'
user = arguments[0]
auth_type = arguments[1]
auth_string = arguments[2]
# check auth type validity
if auth_type not in FakeAuthenticator.valid_auth_types:
return False, user, None, 'invalid auth type'
udata = self.__get_user_data(user)
if udata == None:
return False, user, None, 'invalid user'
uid = udata[2]
if not uid:
self.HostInterface.sessions[self.session]['admin'] = True
else:
self.HostInterface.sessions[self.session]['user'] = True
return True, user, uid, "ok"
class MyRepositoryManager(RepositoryManagerMenu):
def __init__(self, equo, parent):
RepositoryManagerMenu.__init__(self, equo, parent)
def service_status_message(self, e):
if etpUi['debug']:
print_traceback()
def load(self):
""" taken from real class """
self.sm_ui.repositoryManager.show_all()
self.hide_all_data_view_buttons()
# spawn parallel tasks
self.QueueUpdater.start()
self.OutputUpdater.start()
self.PinboardUpdater.start()
# ui will be unlocked by the thread below
self.ui_lock(True)
self.EntropyRepositoryComboLoader.start()
return True
@staticmethod
def init(entropy_client, host, port, username, password, ssl):
import gobject
import gtk
import gtk.gdk
repo = MyRepositoryManager(entropy_client, None)
repo.connection_verification_callback(host, port, username,
password, ssl)
repo.load()
# kill updaters, we don't need them
repo.OutputUpdater.kill()
repo.PinboardUpdater.kill()
repo.QueueUpdater.set_delay(10)
gobject.threads_init()
gtk.gdk.threads_enter()
def do_start():
try:
gtk.main()
except KeyboardInterrupt:
gtk.main_quit()
gtk.gdk.threads_leave()
gobject.timeout_add(1000, do_start)
return repo
def on_repoManagerClose_clicked(self, *args, **kwargs):
""" taken from real class """
self.QueueUpdater.kill()
self.OutputUpdater.kill()
self.PinboardUpdater.kill()
self.destroy()
raise SystemExit(0)
class RepomanTest(unittest.TestCase):
def setUp(self):
self.start_repoman_srv = True
self.host = 'localhost'
self.port = 1027
self.ssl = False
self.username = 'root'
self.password = 'fakefakefake'
# enable debug mode ?
etpUi['debug'] = False
# Server-side logging to stdout, if False, logs will be in socket.log
# otherwise pushed to stdout
self.stdout_logging = False
self.repoman_srv_pid = None
if self.start_repoman_srv:
try:
self.repoman_srv_pid = self.load_repoman_service()
except AssertionError:
self.kill_repoman_service()
raise
from entropy.client.interfaces import Client
self.RepoMan = MyRepositoryManager.init(Client(), self.host,
self.port, self.username, self.password, self.ssl)
def wait_for_connection(self, i_want_conn_enabled = True):
retries = 30
while retries:
retries -= 1
time.sleep(1.0)
try:
sock = socket.create_connection((self.host, self.port),
timeout = 1.0)
except socket.error as err:
if not i_want_conn_enabled:
return True
if err.errno == 111:
continue # retry
raise
sock.close()
if i_want_conn_enabled:
return True
return False
def load_repoman_service(self):
from entropy.server.interfaces import Server
# init with fake repository.
server_intf = Server(fake_default_repo = True)
pid = os.fork()
if pid == 0:
from entropy.services.system.executors import Base
from entropy.services.system.commands import Repository
from entropy.services.system.interfaces import Server as \
ServiceServer
# children
srv = ServiceServer(
Server,
do_ssl = self.ssl,
sock_auth = (FakeAuthenticator, [], {}),
stdout_logging = self.stdout_logging,
external_cmd_classes = [Repository],
external_executor_cmd_classes = [(Base, [], {},)],
entropy_interface_kwargs = {
'community_repo': True,
}
)
srv.port = self.port
try:
srv.go()
except (KeyboardInterrupt, SystemExit,):
srv.killall()
os._exit(0)
srv.killall()
os._exit(0)
# ===> parent
conn_status = self.wait_for_connection()
self.assert_(conn_status)
return pid
def kill_repoman_service(self):
if self.repoman_srv_pid:
os.kill(self.repoman_srv_pid, signal.SIGTERM)
os.kill(self.repoman_srv_pid, signal.SIGKILL)
# get pid, avoid zombies
os.waitpid(self.repoman_srv_pid, 0)
def tearDown(self):
"""
tearDown is run after each test
"""
self.RepoMan.destroy()
self.RepoMan.Service.kill_all_connections()
self.kill_repoman_service()
conn_status = self.wait_for_connection(i_want_conn_enabled = False)
self.assert_(conn_status)
sys.stdout.write("%s ran\n" % (self,))
sys.stdout.flush()
def _test_glsa_data_exec(self, glsa_type):
status, queue_id = self.RepoMan.Service.Methods.get_spm_glsa_data(
glsa_type)
self.assert_(status)
self.assert_(queue_id)
data = self.RepoMan.wait_queue_id_to_complete(queue_id)
def test_queue(self):
status, queue = self.RepoMan.Service.Methods.get_queue()
self.assert_(status)
self.assert_(isinstance(queue, dict))
self.assert_("pause" in queue)
self.assert_("processing_order" in queue)
self.assert_("processing" in queue)
self.assert_("errored_order" in queue)
self.assert_("queue" in queue)
self.assert_("queue_order" in queue)
self.assert_("processed" in queue)
def test_glsa_data_exec_all(self):
self._test_glsa_data_exec("all")
def test_glsa_data_exec_new(self):
self._test_glsa_data_exec("new")
def test_glsa_data_exec_affected(self):
self._test_glsa_data_exec("affected")
def test_available_repos(self):
status, avail_repos = self.RepoMan.Service.Methods.get_available_repositories()
self.assert_(status)
self.assert_(avail_repos)
self.assert_(isinstance(avail_repos, dict))
for repo in avail_repos['available']:
self._run_test_available_packages(repo)
def _run_test_available_packages(self, repoid):
status, repo_data = self.RepoMan.Service.Methods.get_available_entropy_packages(repoid)
self.assert_(status)
self.assert_(isinstance(repo_data, dict))
self.assert_("ordered_idpackages" in repo_data)
self.assert_("data" in repo_data)
self.assert_(isinstance(repo_data["ordered_idpackages"], list))
self.assert_(isinstance(repo_data["data"], dict))
if "__main__" == __name__:
unittest.main()
+8 -9
View File
@@ -2,6 +2,7 @@
../libraries/entropy/transceivers/uri_handlers/skel.py
../libraries/entropy/transceivers/uri_handlers/plugins/factory.py
../libraries/entropy/transceivers/uri_handlers/plugins/__init__.py
../libraries/entropy/transceivers/exceptions.py
../libraries/entropy/transceivers/__init__.py
../libraries/entropy/db/exceptions.py
../libraries/entropy/db/__init__.py
@@ -21,10 +22,6 @@
../libraries/entropy/spm/plugins/interfaces/portage_plugin/xpak.py
../libraries/entropy/spm/plugins/interfaces/portage_plugin/xpaktools.py
../libraries/entropy/spm/plugins/interfaces/__init__.py
../libraries/entropy/services/system/commands.py
../libraries/entropy/services/system/executors.py
../libraries/entropy/services/system/__init__.py
../libraries/entropy/services/system/interfaces.py
../libraries/entropy/services/ugc/commands.py
../libraries/entropy/services/ugc/__init__.py
../libraries/entropy/services/ugc/interfaces.py
@@ -34,6 +31,7 @@
../libraries/entropy/services/authenticators.py
../libraries/entropy/services/auth_interfaces.py
../libraries/entropy/services/commands.py
../libraries/entropy/services/exceptions.py
../libraries/entropy/services/__init__.py
../libraries/entropy/services/interfaces.py
../libraries/entropy/services/skel.py
@@ -47,10 +45,6 @@
../libraries/entropy/client/services/ugc/commands.py
../libraries/entropy/client/services/ugc/__init__.py
../libraries/entropy/client/services/ugc/interfaces.py
../libraries/entropy/client/services/system/commands.py
../libraries/entropy/client/services/system/__init__.py
../libraries/entropy/client/services/system/interfaces.py
../libraries/entropy/client/services/system/methods.py
../libraries/entropy/client/services/__init__.py
../libraries/entropy/client/__init__.py
../libraries/entropy/client/mirrors.py
@@ -83,6 +77,11 @@
../libraries/entropy/qa.py
../libraries/entropy/security.py
../libraries/entropy/tools.py
../libraries/test_db_search.py
../libraries/test_qa.py
../libraries/test_qa_sets.py
../libraries/test_rsync.py
../libraries/test_speed.py
../client/equo.py
../client/text_cache.py
../client/text_configuration.py
@@ -100,7 +99,6 @@
../server/server_key.py
../server/server_query.py
../server/server_reagent.py
../sulfur/src/repo-manager-client.py
../sulfur/src/sulfur_client.py
../sulfur/src/sulfur/core.py
../sulfur/src/sulfur/dialogs.py
@@ -124,5 +122,6 @@
../magneto/src/magneto/core/config.py
../magneto/src/magneto/core/__init__.py
../magneto/src/magneto/core/interfaces.py
../services/kernel-switcher
../sulfur/src/sulfur/sulfur.glade
../magneto/src/magneto/gtk/magneto.glade
+1501 -1536
View File
File diff suppressed because it is too large Load Diff
+1451 -1612
View File
File diff suppressed because it is too large Load Diff
+1510 -1543
View File
File diff suppressed because it is too large Load Diff
+1148 -1513
View File
File diff suppressed because it is too large Load Diff
+1517 -1551
View File
File diff suppressed because it is too large Load Diff
+1453 -1545
View File
File diff suppressed because it is too large Load Diff
+1508 -1544
View File
File diff suppressed because it is too large Load Diff
+1504 -1537
View File
File diff suppressed because it is too large Load Diff
+1509 -1542
View File
File diff suppressed because it is too large Load Diff
+1502 -1535
View File
File diff suppressed because it is too large Load Diff
+1505 -1542
View File
File diff suppressed because it is too large Load Diff
+1510 -1546
View File
File diff suppressed because it is too large Load Diff
+1189 -1519
View File
File diff suppressed because it is too large Load Diff
+1180 -1518
View File
File diff suppressed because it is too large Load Diff
+1514 -1549
View File
File diff suppressed because it is too large Load Diff
-127
View File
@@ -1,127 +0,0 @@
#!/usr/bin/python2
"""
@author: Fabio Erculiani <lxnay@sabayon.org>
@contact: lxnay@sabayon.org
@copyright: Fabio Erculiani
@license: GPL-2
B{Entropy Package Manager Service}.
"""
import os
import sys
import time
import signal
import threading
sys.path.insert(0,'/usr/lib/entropy/libraries')
sys.path.insert(0,'/usr/lib/entropy/client')
sys.path.insert(0,'../libraries')
sys.path.insert(0,'../client')
# disable pid management
sys.argv.append("--no-pid-handling")
do_ssl = False
do_stdout_logging = True
community_repo = False
do_port = 1027
from entropy.i18n import _
from entropy.const import etpConst
etpConst['community']['mode'] = community_repo
etpConst['socket_service']['session_ttl'] = 300
from entropy.core.settings.base import SystemSettings
SysSettings = SystemSettings()
from entropy.tools import get_year, print_traceback
from entropy.output import nocolor
from text_tools import print_menu
myopts = [
None,
(0," ~ "+SysSettings['system']['name']+" ~ "+sys.argv[0]+" ~ ",1,'Repository Administration daemon - (C) %s' % (get_year(),) ),
None,
(0,_('Basic Options'),0,None),
None,
(1,'--help',2,_('this output')),
(1,'--nocolor',1,_('disable colorized output')),
None,
(0,_('Application Options'),0,None),
None,
(1,'--ssl',2,_('enable SSL service too')),
(1,'--nostdout',1,_('disable output to stdout, redirect to log file')),
(1,'--community',1,_('this service hosts a community repository')),
(1,'--port=N',1,_('specify listening port (SSL will be N+1)')),
None,
]
if "--nocolor" in sys.argv:
nocolor()
if "--help" in sys.argv:
print_menu(myopts)
raise SystemExit(1)
if "--ssl" in sys.argv:
do_ssl = True
if "--nostdout" in sys.argv:
do_stdout_logging = False
if "--community" in sys.argv:
community_repo = True
if "--port" in sys.argv:
idx = sys.argv.index("--port")+1
try:
do_port = int(sys.argv[idx])
except (IndexError, ValueError,):
pass
from entropy.services.system.interfaces import Server as ServiceServer
from entropy.services.system.executors import Base
from entropy.services.system.commands import Repository
from entropy.server.interfaces import Server
from entropy.misc import ParallelTask
def kill_threads():
for th in threading.enumerate():
if hasattr(th, 'kill'):
th.kill()
def term_myself():
os.kill(os.getpid(), signal.SIGTERM)
def run_srv(s):
try:
s.go()
except:
print_traceback()
raise
finally:
if s is not None:
s.killall()
kill_threads()
term_myself()
srv = ServiceServer(
Server,
do_ssl = do_ssl,
stdout_logging = do_stdout_logging,
external_cmd_classes = [Repository],
external_executor_cmd_classes = [(Base,[],{},)],
entropy_interface_kwargs = {
'community_repo': etpConst['community']['mode']
}
)
srv.port = do_port
thread_names = ["system_socket"]
task = ParallelTask(run_srv, srv)
task.setName(thread_names[0])
task.start()
try:
while task.isAlive():
time.sleep(2)
finally:
if srv is not None:
srv.killall()
kill_threads()
term_myself()
-44
View File
@@ -1,44 +0,0 @@
#!/sbin/runscript
# Copyright 2009 Fabio Erculiani
# Distributed under the terms of the GNU General Public License v2
DAEMON_EXEC="/usr/sbin/repository-admin-daemon"
PID="/var/run/entropy_repo_admin.pid"
CMDLINE="--nostdout"
depend() {
use dns net localmount netmount nfsmount hostname
}
start() {
ebegin "Starting Entropy system daemon"
start-stop-daemon --background --make-pidfile --start --pidfile ${PID} --quiet --exec ${DAEMON} -- ${CMDLINE}
sleep 3
if [ -f "${PID}" ]; then
if [ -d "/proc/$(cat ${PID})" ]; then
eend 0
else
eend 1
fi
else
eend 1
fi
}
stop() {
ebegin "Stopping Entropy system daemon"
if [ -f "${PID}" ]; then
mypid=$(cat $PID 2&> /dev/null)
if [ -d "/proc/$(cat ${mypid})" ]; then
eend 0
else
eend 1
fi
else
eend 1
fi
}
-113
View File
@@ -1,113 +0,0 @@
#!/usr/bin/python2
import os
import sys
import time
import signal
import threading
sys.path.insert(0,'/usr/lib/entropy/libraries')
sys.path.insert(0,'/usr/lib/entropy/client')
sys.path.insert(0,'../libraries')
sys.path.insert(0,'../client')
# disable pid management
sys.argv.append("--no-pid-handling")
do_ssl = False
do_stdout_logging = True
do_port = 1027
from entropy.i18n import _
from entropy.const import etpConst
etpConst['socket_service']['session_ttl'] = 300
# listen on all the avail. interfaces
etpConst['socket_service']['hostname'] = "*"
from entropy.core.settings.base import SystemSettings
SysSettings = SystemSettings()
from entropy.tools import get_year, print_traceback
from entropy.output import nocolor
from text_tools import print_menu
myopts = [
None,
(0," ~ "+SysSettings['system']['name']+" ~ "+sys.argv[0]+" ~ ",1,'Service test daemon - (C) %s' % (get_year(),) ),
None,
(0,_('Basic Options'),0,None),
None,
(1,'--help',2,_('this output')),
(1,'--nocolor',1,_('disable colorized output')),
None,
(0,_('Application Options'),0,None),
None,
(1,'--ssl',2,_('enable SSL service too')),
(1,'--nostdout',1,_('disable output to stdout, redirect to log file')),
(1,'--community',1,_('this service hosts a community repository')),
(1,'--port=N',1,_('specify listening port (SSL will be N+1)')),
None,
]
if "--nocolor" in sys.argv:
nocolor()
if "--help" in sys.argv:
print_menu(myopts)
raise SystemExit(1)
if "--ssl" in sys.argv:
do_ssl = True
if "--nostdout" in sys.argv:
do_stdout_logging = False
if "--community" in sys.argv:
community_repo = True
if "--port" in sys.argv:
idx = sys.argv.index("--port")+1
try:
do_port = int(sys.argv[idx])
except (IndexError, ValueError,):
pass
from entropy.services.test.interfaces import Server as ServiceServer
from entropy.services.test.commands import Test
from entropy.misc import ParallelTask
def kill_threads():
for th in threading.enumerate():
if hasattr(th, 'kill'):
th.kill()
def term_myself():
os.kill(os.getpid(), signal.SIGTERM)
def run_srv(s):
try:
s.go()
except:
print_traceback()
raise
finally:
if s is not None:
s.killall()
kill_threads()
term_myself()
srv = ServiceServer(
do_ssl = do_ssl,
external_cmd_classes = [Test],
stdout_logging = do_stdout_logging,
entropy_interface_kwargs = {
'community_repo': etpConst['community']['mode']
}
)
srv.port = do_port
thread_names = ["system_socket"]
task = ParallelTask(run_srv, srv)
task.setName(thread_names[0])
task.start()
try:
while task.isAlive():
time.sleep(2)
finally:
if srv is not None:
srv.killall()
kill_threads()
term_myself()
-1
View File
@@ -34,7 +34,6 @@ install:
mkdir -p $(DESTDIR)/etc
mkdir -p $(DESTDIR)/etc/pam.d
install -m755 $(MISCDIR)/entropy-repo-manager $(DESTDIR)$(BINDIR)/.
install -m755 $(MISCDIR)/sulfur $(DESTDIR)$(BINDIR)/.
install -m755 $(MISCDIR)/sulfur-uri-handler $(DESTDIR)$(BINDIR)/.
install -m644 $(MISCDIR)/entropy-handler.schemas $(DESTDIR)/etc/gconf/schemas/.
-4
View File
@@ -1,4 +0,0 @@
#!/usr/bin/python2
import subprocess
rc = subprocess.call(["python2","/usr/lib/entropy/repoman/repo-manager-client.py"])
raise SystemExit(rc)
-9
View File
@@ -1,9 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=Entropy Development Repository Manager
Comment=Entropy Graphical Repository Manager
Categories=Application;Development
Icon=/usr/share/pixmaps/sulfur/sulfur-icon.png
Exec=entropy-repo-manager %U
Type=Application
Terminal=false
-3
View File
@@ -14,6 +14,3 @@ install:
install -m644 sulfur/*.py $(DESTDIR)/$(PKGDIR)/.
install -m644 sulfur/revision $(DESTDIR)/$(PKGDIR)/.
install -m644 sulfur/*.glade $(DESTDIR)/$(PKGDIR)/.
install -m755 repo-manager-client.py $(DESTDIR)/$(REPOMANDIR)/..
install -m644 repoman/*.py $(DESTDIR)/$(REPOMANDIR)/.
-96
View File
@@ -1,96 +0,0 @@
# -*- coding: utf-8 -*-
"""
@author: Fabio Erculiani <lxnay@sabayon.org>
@contact: lxnay@sabayon.org
@copyright: Fabio Erculiani
@license: GPL-2
B{Entropy Package Manager Graphical Repository Administration tool}.
"""
# Base Python Imports
import sys
# Entropy Imports
if "--debugdev" not in sys.argv:
sys.path.insert(0, "/usr/lib/entropy/repoman")
sys.path.insert(0, "/usr/lib/entropy/sulfur")
sys.path.insert(0, "/usr/lib/entropy/client")
sys.path.insert(0, "/usr/lib/entropy/libraries")
sys.path.insert(0, "../../libraries")
sys.path.insert(0, "../../client")
sys.path.insert(0, "sulfur")
sys.path.insert(0, "repoman")
# Sulfur Imports
import gtk, gobject
from sulfur.setup import const
from sulfur.dialogs import ExceptionDialog
from sulfur.entropyapi import Equo
from repoman import RepositoryManagerMenu
class MyRepositoryManager(RepositoryManagerMenu):
def __init__(self, equo, parent):
RepositoryManagerMenu.__init__(self, equo, parent)
def on_repoManagerClose_clicked(self, *args, **kwargs):
self.QueueUpdater.kill()
self.OutputUpdater.kill()
self.PinboardUpdater.kill()
self.destroy()
raise SystemExit(1)
class ManagerApplication:
def __init__(self):
self._entropy = Equo()
self.ui = None
self.progress_log_write = sys.stdout
self.std_output = sys.stdout
self.progress = None
self._entropy.connect_to_gui(self)
def init(self):
mymenu = MyRepositoryManager(self._entropy, None)
rc_status = mymenu.load()
if not rc_status:
del mymenu
raise SystemExit(1)
def destroy(self):
self._entropy.shutdown()
def dummy_func(self, *args, **kwargs):
pass
if __name__ == "__main__":
try:
try:
gtk.window_set_default_icon_from_file(
const.PIXMAPS_PATH+"/sulfur-icon.png")
except gobject.GError:
pass
main_app = ManagerApplication()
main_app.init()
gobject.threads_init()
gtk.gdk.threads_enter()
gtk.main()
gtk.gdk.threads_leave()
from sulfur.entropyapi import Equo
Equo().shutdown()
except SystemExit:
print("Quit by User")
main_app.shutdown()
raise SystemExit(0)
except KeyboardInterrupt:
print("Quit by User (KeyboardInterrupt)")
main_app.shutdown()
raise SystemExit(0)
except: # catch other exception and write it to the logger.
my = ExceptionDialog()
my.show()
raise SystemExit(0)
File diff suppressed because it is too large Load Diff