def add_access_identifier(self,access_ident):
		"""
		Add an accessIdentifier to the domain.
		1. Check if it exists already
		2. Add it
		
		Return value: 0 = Succes, <0 = failure
		"""
		res = self.l.search(conf.get('LDAPSERVER','basedn'),\
		                   ldap.SCOPE_BASE,'(objectClass=skoleSysDomain)',['accessIdentifier'])
		sres = self.l.result(res,0)
		if sres[1]==[]:
			# The domain entry does not exist probably missing the skoleSysDomain objectClass
			return -13501

		attribs = sres[1][0][1]
		path = sres[1][0][0]

		access = [access_ident]
		if attribs.has_key('accessIdentifier'):
			if attribs['accessIdentifier'].count(access_ident):
				# Access identifier already exists on this domain
				return -13502
			access += attribs['accessIdentifier']
		# Add it
		try:
			self.bind(conf.get('LDAPSERVER','admin'),conf.get('LDAPSERVER','passwd'))
			self.touch_by_dict({path:{'accessIdentifier':access}})
		except Exception, e:
			print e
			return -13503		
Exemplo n.º 2
0
def onCommandAlias(e):
    if e.args and 'r' in e.switches:
        name = e.args[0].lower()
        command = aliases[name]
        del aliases[name]
        conf['aliases'] = aliases
        e.window.write("* Deleted alias %s%s (was %s)" % (conf.get('command-prefix','/'),name,command))
        events.load(__name__,reloading=True)
    elif 'l' in e.switches:
        e.window.write("* Current aliases:")
        for i in aliases:
            e.window.write("*  %s%s: %s" % (conf.get('command-prefix','/'),i,aliases[i]))
    elif len(e.args) >= 2:
        name = e.args[0].lower()
        command = ' '.join(e.args[1:])
        aliases[name] = command
        conf['aliases'] = aliases
        e.window.write("* Created an alias %s%s to %s" % (conf.get('command-prefix','/'),name,command))
        events.reload(__name__)
    elif len(e.args) == 1:
        name = e.args[0].lower()
        if name in aliases:
            e.window.write("* %s%s is an alias to %s" % (conf.get('command-prefix','/'),name,aliases[name]))
        else:
            e.window.write("* There is no alias %s%s" % (conf.get('command-prefix','/'),name))
    else:
        e.window.write(
"""Usage:
 /alias \x02name\x02 \x02expression\x02 to create or replace an alias
 /alias \x02name\x02 to look at an alias
 /alias -r \x02name\x02 to remove an alias
 /alias -l to see a list of aliases""")
Exemplo n.º 3
0
	def remove_host(self,hwaddr=None, hostname=None):
		"""
		Remove a registered SkoleSYS host from LDAP
		"""
		hostspath = "%s,%s" % (conf.get('LDAPSERVER','hosts_ou'),conf.get('LDAPSERVER','basedn'))
		if hwaddr:
			hwaddr = hostdef.check_hwaddr(hwaddr)
			if not hwaddr:
				return -1
			res = self.l.search(hostspath,\
					ldap.SCOPE_ONELEVEL,'(& (macAddress=%s)(objectclass=skoleSysHost))'%hwaddr,['dn'])
			sres = self.l.result(res,0)
			if sres[1]==[]:
				return -2
			dn = sres[1][0][0]
			
		if hostname:
			res = self.l.search(hostspath,\
					ldap.SCOPE_ONELEVEL,'(& (hostName=%s)(objectclass=skoleSysHost))'%hostname,['dn'])
			sres = self.l.result(res,0)
			if sres[1]==[]:
				return -3
			dn = sres[1][0][0]
		
		self.bind(conf.get('LDAPSERVER','admin'),conf.get('LDAPSERVER','passwd'))
		self.delete(dn)
		return 0
Exemplo n.º 4
0
	def groupdel(self,uid,groupname):
		# Do not check if the user exists, just remove the uid
		#res = self.l.search(conf.get('LDAPSERVER','basedn'),ldap.SCOPE_SUBTREE,'(& (uid=%s) (objectclass=posixaccount))'%uid,['dn'])
		#sres = self.l.result(res,0)
		#if sres[1]==[]:
		#	return -10401
		res = self.l.search(conf.get('LDAPSERVER','basedn'),ldap.SCOPE_SUBTREE,'(& (cn=%s) (objectclass=posixgroup))'%groupname,['memberuid'])
		sres = self.l.result(res,0)
		if sres[1]==[]:
			return -10402
		attribs = sres[1][0][1]
		path = sres[1][0][0]
		if attribs.has_key('memberUid'):
			if attribs['memberUid'].count(uid):
				memberuid = attribs['memberUid']
				memberuid.remove(uid)
			else: return -10403
		else: return -10403
			
		try:
			self.bind(conf.get('LDAPSERVER','admin'),conf.get('LDAPSERVER','passwd'))
			self.touch_by_dict({path:{'memberuid':memberuid}})
		except Exception, e:
			print e
			return -10404
Exemplo n.º 5
0
def default_nicks():
    try:
        nicks = [conf.get('nick')] + conf.get('altnicks', [])
        if not nicks[0]:

            # We're going to generate a nick based on the user's nick name
            # and their public key.
            import sugar.profile
            import hashlib

            user_name = sugar.profile.get_nick_name()
            pubkey = sugar.profile.get_pubkey()
            m = hashlib.sha1()
            m.update(pubkey)
            hexhash = m.hexdigest()

            # Okay.  Get all of the alphabetic bits of the username:
            user_name_letters = "".join([x for x in user_name if x.isalpha()])

            # If that came up with nothing, make it 'XO'.  Also, shorten it
            # if it's more than 11 characters (as we need 5 for - and the
            # hash).
            if len(user_name_letters) == 0:
                user_name_letters = "XO"
            if len(user_name_letters) > 11:
                user_name_letters = user_name_letters[0:11]

            # Finally, generate a nick by using those letters plus the first
            # four hash bits of the user's public key.
            user_nick = user_name_letters + "-" + hexhash[0:4]

            nicks = [user_nick]
    except:
        nicks = ["purk"]
    return nicks
	def remove_access_identifier(self,access_ident):
		"""
		Remove an accessIdentifier from the domain. This method will also remove
		the accessIdentifier from any user who has it granted.
		1. Check if it exists
		2. Remove it from domain
		3. Remove it from users
		
		Return value: 0 = Succes, <0 = failure
		"""		
		res = self.l.search(conf.get('LDAPSERVER','basedn'),\
			ldap.SCOPE_SUBTREE,'(accessIdentifier=%s)' % access_ident,['dn','accessIdentifier'])
		
		sres = self.l.result(res,1)
		self.bind(conf.get('LDAPSERVER','admin'),conf.get('LDAPSERVER','passwd'))
		if not len(sres[1]):
			# Access identifer does not exist on the domain
			return -13601

		for entry in sres[1]:
			path = entry[0]
			attribs = entry[1]

			access = attribs['accessIdentifier']
			access.remove(access_ident)
			if not len(access):
				access = None
			try:
				self.touch_by_dict({path:{'accessIdentifier':access}})
			except Exception, e:
				print e
				return -13602
Exemplo n.º 7
0
def default_nicks():
    try:
        nicks = [conf.get('nick')] + conf.get('altnicks', [])
        if not nicks[0]:

            # We're going to generate a nick based on the user's nick name
            # and their public key.
            from sugar3 import profile
            import hashlib

            user_name = profile.get_nick_name()
            pubkey = profile.get_pubkey()
            m = hashlib.sha1()
            m.update(pubkey)
            hexhash = m.hexdigest()

            # Okay.  Get all of the alphabetic bits of the username:
            user_name_letters = "".join([x for x in user_name if x.isalpha()])

            # If that came up with nothing, make it 'XO'.  Also, shorten it
            # if it's more than 11 characters (as we need 5 for - and the
            # hash).
            if len(user_name_letters) == 0:
                user_name_letters = "XO"
            if len(user_name_letters) > 11:
                user_name_letters = user_name_letters[0:11]

            # Finally, generate a nick by using those letters plus the first
            # four hash bits of the user's public key.
            user_nick = user_name_letters + "-" + hexhash[0:4]

            nicks = [user_nick]
    except:
        nicks = ["purk"]
    return nicks
Exemplo n.º 8
0
    def __init__(self, host: str = None, port: int = None, cert_path: str = None, macaroon_path: str = None):
        self._host = host or conf.get('LND_HOST')
        self._port = port or conf.get('LND_PORT')
        self._cert_path = cert_path or conf.get('LND_CERT_PATH')
        self._macaroon_path = macaroon_path or conf.get('LND_MACAROON_PATH')

        self._encoded_macaroon = codecs.encode(open(conf.get('LND_MACAROON_PATH'), 'rb').read(), 'hex')

        self._base_url = f'https://{self._host}:{self._port}/v1'
Exemplo n.º 9
0
def default_nicks():
    try:
        nicks = [conf.get('nick')] + conf.get('altnicks',[])
        if not nicks[0]:
            import getpass
            nicks = [getpass.getuser()]
    except:
        nicks = ["mrurk"]
    return nicks
Exemplo n.º 10
0
def onCommandThemeinfo(e):
    e.window.write('%s %s by %s(Contact information: %s). Description: %s' % (conf.get('theme','Default'), theme.get('Version',default.get('Version','vX')), theme.get('Author',default.get('Author','unknown')), theme.get('Contact',default.get('Contact','None')), theme.get('Description',default.get('Description','None'))))
    info = 'Events Themed: '
    if conf.get('theme'):
        for event in theme:
            info += event+', '
    else:
        for event in default:
            info += event+', '
    e.window.write('%s (Themed/Total: %s/%s)' % (info[:len(info)-2], repr(len(theme)), repr(len(default))))
Exemplo n.º 11
0
def autoconnect_set_data(do_autoconnect, network): 
    if 'start_networks' not in conf:
        conf['start_networks'] = []

    # note (n in C) != w
    if (network in conf.get('start_networks')) != do_autoconnect:
        if do_autoconnect:
            conf.get('start_networks').append(network)
        else:
            conf.get('start_networks').remove(network)
Exemplo n.º 12
0
	def removegroup(self,groupname,backup_home,remove_home):
		"""
		Remove a group 
		Setting backup_home to True will create a tarball backup of the group's homedir
		Setting remove_home to True truncate the gruop's homedir
		"""
		# check if the group exists
		res = self.l.search(conf.get('LDAPSERVER','basedn'),\
			ldap.SCOPE_SUBTREE,'(& (cn=%s)(objectclass=posixgroup))'%groupname,['dn','memberuid'])
		sres = self.l.result(res,0)
		if sres[1]==[]:
			return -1
	
		services = self.list_services(groupname)
		if type(services) == list:
			# service group
			for sname in services:
				self.detach_service(groupname,sname)
	
		if sres[1][0][1].has_key('memberUid'):
			import usermanager as uman
			um = uman.UserManager()
			for uid in sres[1][0][1]['memberUid']:
				um.groupdel(uid,groupname)
		
		path = sres[1][0][0]
		self.bind(conf.get('LDAPSERVER','admin'),conf.get('LDAPSERVER','passwd'))
		self.delete(path)
		
		group_path = "%s/%s/groups/%s" % (conf.get('DOMAIN','domain_root'),conf.get('DOMAIN','domain_name'),groupname)
		if os.path.exists(os.path.normpath(group_path)):
			# The group has a homedir, maybe do stuff...
			if backup_home:
				try:
					print "Backing up the group home folder of \"%s\"..." % groupname
					cnt = 0
					cnt_str = ''
					backup_path = "%s.bz2" % (os.path.normpath(group_path))
					while os.path.exists(backup_path):
						cnt+=1
						cnt_str = str(cnt)
						backup_path = "%s_%s.bz2" % (os.path.normpath(group_path),cnt_str)
						
					os.system('tar cjpf %s %s' % (backup_path,os.path.normpath(group_path)))
				except Exception, e:
					print e
					return -2
			if remove_home:
				try:
					print "Deleting the group home folder of \"%s\"..." % groupname
					os.system('rm %s -R -f' % (os.path.normpath(group_path)))
				except Exception, e:
					print e
					return -3
Exemplo n.º 13
0
def autoconnect_set_data(do_autoconnect, network): 
    if 'start_networks' not in conf:
        conf['start_networks'] = []

    # note (n in C) != w
    if (network in conf.get('start_networks')) != do_autoconnect:
        if do_autoconnect:
            conf.get('start_networks').append(network)
        else:
            conf.get('start_networks').remove(network)
    save_config()
Exemplo n.º 14
0
	def ipaddr_exists(self,ipaddr):
		"""
		check if a ip address is already statically reserved to a certain host
		"""
		hostspath = "%s,%s" % (conf.get('LDAPSERVER','hosts_ou'),conf.get('LDAPSERVER','basedn'))
		res = self.l.search(hostspath,\
				ldap.SCOPE_ONELEVEL,'(& (ipHostNumber=%s)(objectclass=skoleSysHost))'%ipaddr,['cn'])
		sres = self.l.result(res,0)
		if sres[1]==[]:
			return False
		return True	
Exemplo n.º 15
0
	def deluser(self,uid,backup_home,remove_home):
		res = self.l.search(conf.get('LDAPSERVER','basedn'),ldap.SCOPE_SUBTREE,'uid=%s'%uid,['dn'])
		sres = self.l.result(res,0)
		if sres[1]==[]:
			return -10201
		try:
			self.bind(conf.get('LDAPSERVER','admin'),conf.get('LDAPSERVER','passwd'))
			self.delete(sres[1][0][0])
		except Exception, e:
			print e
			return -10202
Exemplo n.º 16
0
    def __init__(self, win):
        if conf.get('colind-title'):
            height = 67
        else:
            height = 46
        self.win = win
        self.window = gtk.Window(gtk.WINDOW_POPUP)
        winx = windows.manager.get_position()[0] + win.input.get_allocation().x + 5
        winy = windows.manager.get_position()[1] + win.input.get_allocation().y - height + 22
        self.window.move(winx,winy)
        self.window.set_title('Color Index')
        self.window.set_size_request(174,height)
        self.window.set_border_width(3)

        all = gtk.VBox(True, 2)
        self.window.add(all)

        if conf.get('colind-title'):
            toolbar = gtk.HBox(False)
            all.pack_start(toolbar)
            tool_lab = gtk.Label('Color Index')
            tool_lab.set_size_request(149,19)
            tool_event = gtk.EventBox()
            toolbar.pack_start(tool_lab)
            toolbar.pack_start(tool_event)
            tool_but = gtk.Label('X')
            tool_event.add(tool_but)
            tool_event.set_events(gtk.gdk.BUTTON_PRESS_MASK)
            tool_event.connect('button_press_event', self.select)

        top_row = gtk.HBox(True, 2)
        bot_row = gtk.HBox(True, 2)
        all.pack_start(top_row)
        all.pack_start(bot_row)

        event_box = []
        color_lab = []
        for col in range(16):
            event_box.append(gtk.EventBox())
            if col < 8:
                top_row.pack_start(event_box[col])
            else:
                bot_row.pack_start(event_box[col])
            color_lab.append(gtk.Label(str(col).zfill(2)))
            event_box[col].add(color_lab[col])
            event_box[col].set_events(gtk.gdk.BUTTON_PRESS_MASK)
            event_box[col].connect('button_press_event', self.select, str(col).zfill(2))
            event_box[col].modify_bg(gtk.STATE_NORMAL,event_box[col].get_colormap().alloc_color(parse_mirc.colors[col]))
        self.window.show_all()
        self.window.window.set_keep_above(True)
	def add_machine(self,netbiosname,ntdomain):
		hostspath = conf.get('LDAPSERVER','basedn')
		res = self.l.search(hostspath,\
				ldap.SCOPE_ONELEVEL,'(&(objectclass=sambaDomain)(sambaDomainName=%s))'% ntdomain ,['sambaSID'])
		sres = self.l.result(res,0)
		if sres[1]==[]:
			return -1 # Domain does not exist
		machine_info = {
			'sambaSID': '%s-' % sres[1][0][1]['sambaSID'][0],
			'uid': netbiosname,
			'cn': netbiosname,
			'gidNumber': '2005',
			'homeDirectory': '/dev/null',
			'sambaAcctFlags': '[W]',
			'objectClass': ['sambaSamAccount','posixAccount','account','top'],
			'uidNumber':str(self.max(conf.get('LDAPSERVER','basedn'),
				'objectclass=posixaccount','uidNumber',
				int(conf.get('DOMAIN','uid_start')))+1)}
				
		path = "%s,%s,%s,%s" % \
		  ('uid=%s'%netbiosname,\
		   conf.get('LDAPSERVER','smb_machines_ou'),\
		   conf.get('LDAPSERVER','samba_ou'),\
		   conf.get('LDAPSERVER','basedn'))
		
		self.bind(conf.get('LDAPSERVER','admin'),conf.get('LDAPSERVER','passwd'))
		self.touch_by_dict({path:machine_info})
Exemplo n.º 18
0
def onConnect(e):
    if conf.get('debug'):
        debug = get_debug(e.network)
        if debug:
            windows.mutate(DebugWindow, e.network, debug.id)
        else:
            events.run('debug', e.window, e.network)
Exemplo n.º 19
0
def insert_depth_data(item):
    """保存深度统计"""
    # 跳过start_coords为0的数据
    start = item.get('start_coords')
    if start == 0:
        return
    end = item.get('end_coords')
    barcode = item.get('barcode')
    ont_conf = conf.get('ont')
    depth_position_step = ont_conf.get('depth_position_step')
    read_length_step = ont_conf.get('depth_read_length_step')
    # 计算位置
    if start % depth_position_step == 0 and start != 0:
        r_start = int(start / depth_position_step) - 1
    else:
        r_start = math.floor(start / depth_position_step)
    r_end = math.ceil(end / depth_position_step)
    # 计算读长
    read_len = math.ceil(item.get('read_len') / read_length_step)
    # 保存数据
    for i in range(r_start, r_end):
        for ii in range(0, read_len):
            key = '%s_%s_%s' % (i, barcode, ii)
            redis_cli.hincrby('CELL:DEPTH:%s' % cell(item.get('path')), key)
    for i in range(1, r_end):
        for ii in range(0, read_len):
            key = '%s_%s_%s' % (i, barcode, ii)
            redis_cli.hsetnx('CELL:DEPTH:%s' % cell(item.get('path')), key, 0)
Exemplo n.º 20
0
 def open_file(filename):
     flags = gobject.SPAWN_LEAVE_DESCRIPTORS_OPEN | gobject.SPAWN_SEARCH_PATH
     filename = str(filename) #gobject won't accept unicode strings
     if conf.get('open-file-command'):
         command = conf['open-file-command'].split(' ') + [filename]
         try:
             gobject.spawn_async(command,flags=flags)
         except OSError:
             print "Unable to start %s" % command
     elif open_file_cmd:
         try:
             command = open_file_cmd + (filename,)
             gobject.spawn_async(command,flags=flags)
         except OSError:
             print "Unable to start %s" % command
     else:
         paths = os.getenv("PATH") or os.defpath
         for cmdfile, cmd in os_commands:
             for path in paths.split(os.pathsep):
                 if os.access(os.path.join(path,cmdfile),os.X_OK):
                     globals()['open_file_cmd'] = cmd
                     try:
                         command = cmd + (filename,)
                         gobject.spawn_async(command,flags=flags)
                     except OSError:
                         print "Unable to start %s" % command
                     return
         print "Unable to find a method to open %s." % filename
Exemplo n.º 21
0
def onDisconnect(e):
    if hasattr(e.network, '_reconnect_source'):
        e.network._reconnect_source.unregister()
        del e.network._reconnect_source
    if hasattr(e.network, 'connect_timestamp'):
        if e.error and conf.get('autoreconnect', True):
            delay = time.time() - \
                e.network.connect_timestamp > 30 and 30 or 120

            def do_reconnect():
                if not e.network.status:
                    server(network=e.network)

            def do_announce_reconnect():
                if not e.network.status:
                    windows.get_default(
                        e.network).write(
                        "* Will reconnect in %s seconds.." %
                        delay)
                    e.network._reconnect_source = ui.register_timer(
                        delay *
                        1000,
                        do_reconnect)
            e.network._reconnect_source = ui.register_idle(
                do_announce_reconnect)
Exemplo n.º 22
0
def get_autojoin_list(network):
    perform = conf.get('networks', {}).get(network.name, {}).get('perform', ())
    channels = set()
    for line in perform:
        if line.startswith('join ') and ' ' not in line[5:]:
            channels.update(line[5:].split(','))
    return channels
Exemplo n.º 23
0
def get_autojoin_list(network):
    perform = conf.get('networks',{}).get(network.name,{}).get('perform',())
    channels = set()
    for line in perform:
        if line.startswith('join ') and ' ' not in line[5:]:
            channels.update(line[5:].split(','))
    return channels
Exemplo n.º 24
0
def onSocketConnect(e):
    timeout = conf.get("server_traffic_timeout", 120)*1000
    e.network._message_timeout = False
    if timeout:
        e.network._message_timeout_source = ui.register_timer(timeout, check_timeout, e.network)
    else:
        e.network._message_timeout_source = None
Exemplo n.º 25
0
 def __init__(self, server="irc.default.org", port=6667, nicks=[], 
                 username="", fullname="", name=None, **kwargs):
     self.server = server
     self.port = port
     
     self.name = name or server
     
     self.nicks = nicks or default_nicks()
     self.me = self.nicks[0]
     
     self.username = username or "urk"
     self.fullname = fullname or conf.get("fullname", self.username)
     self.password = ''
     
     self.isupport = {
         'NETWORK': server, 
         'PREFIX': '(ohv)@%+',
         'CHANMODES': 'b,k,l,imnpstr',
     }
     self.prefixes = {'o':'@', 'h':'%', 'v':'+', '@':'o', '%':'h', '+':'v'}
     
     self.status = DISCONNECTED
     self.failedhosts = [] #hosts we've tried and failed to connect to
     self.channel_prefixes = '&#+$'   # from rfc2812
     
     self.on_channels = set()
     self.requested_joins = set()
     self.requested_parts = set()
     
     self.buffer = ''
Exemplo n.º 26
0
def onClose(e):
    nwindows = list(windows.get_with(network=e.window.network))
    
    if isinstance(e.window, windows.ChannelWindow): 
        cwindows = list(windows.get_with(
                            network=e.window.network,
                            wclass=windows.ChannelWindow
                            ))
        
        #if we only have one window for the network, don't bother to part as
        # we'll soon be quitting anyway
        if len(nwindows) != 1 and irc_script.ischan(e.window.network, e.window.id):
            e.window.network.part(e.window.id) 
    
    if len(nwindows) == 1:
        events.trigger("CloseNetwork", window=e.window, network=e.window.network)
    
    elif isinstance(e.window, windows.StatusWindow) and conf.get('status'):
        events.trigger("CloseNetwork", window=e.window, network=e.window.network)
        for window in nwindows:
            if window != e.window:
                window.close()
        
    if len(windows.manager) == 1:
        windows.new(windows.StatusWindow, irc.Network(), "status")
Exemplo n.º 27
0
def transform_bcolor(start, end):
    if (start.get('background',99) != end.get('background',99)):
        confcolors = conf.get('colors', colors)
        result = start.copy()
        if 'foreground' in end:
            try:
                fg_index = list(confcolors).index(end['foreground'].upper())
            except ValueError:
                return '','',start
            result['foreground'] = end['foreground']
        else:
            fg_index = 99
            result.pop('foreground',None)
        if 'background' in end:
            try:
                bg_index = list(confcolors).index(end['background'].upper())
            except ValueError:
                return '','',start
            result['background'] = end['background']
        else:
            bg_index = 99
            del result['background']
        return '\x03%02i,%02i' % (fg_index, bg_index), ',', result
    else:
        return '','',start
Exemplo n.º 28
0
	def restart_service(self,groupname,servicename):
		"""
		Restart service taking new rescent changes in use.
		"""
		res = self.l.search(conf.get('LDAPSERVER','basedn'),\
			ldap.SCOPE_SUBTREE,'(& (cn=%s)(objectclass=skoleSysServiceGroup))'%groupname,['dn','memberuid','servicelist'])
	
		sres = self.l.result(res,0)
		if sres[1]==[]:
			return -1 # Group does not exist
	
		dn = sres[1][0][0]
		servicelist = []
		if sres[1][0][1].has_key('serviceList'):
			servicelist = sres[1][0][1]['serviceList']
		
		if not servicelist.count(servicename):
			return -4 # Group is not attached to the service
		
		import skolesys.services as s
		if not s.groupservices().count(servicename):
			return -2 # the service does not exist
		service_inst = s.create_groupserviceinterface(servicename,groupname)
		if not service_inst:
			return -3 # the service failed to load
		
		return service_inst.restart()
Exemplo n.º 29
0
    def edit_network(self, cell, path_string, new_text):
        network_list = self.networks.get_model()
        old_text = network_list[path_string][0]
        
        networks = conf.get('networks')
        networks[new_text] = networks.pop(old_text, {})

        start_networks = conf.get('start_networks', [])
        if old_text in start_networks:
            start_networks[start_networks.index(old_text)] = new_text

        iter = network_list.get_iter_from_string(path_string)
        network_list.set_value(iter, 0, new_text)

        self.infobox.network = new_text
        save_config()
Exemplo n.º 30
0
def transform_bcolor(start, end):
    if (start.get('background', 99) != end.get('background', 99)):
        confcolors = conf.get('colors', colors)
        result = start.copy()
        if 'foreground' in end:
            try:
                fg_index = list(confcolors).index(end['foreground'].upper())
            except ValueError:
                return '', '', start
            result['foreground'] = end['foreground']
        else:
            fg_index = 99
            result.pop('foreground', None)
        if 'background' in end:
            try:
                bg_index = list(confcolors).index(end['background'].upper())
            except ValueError:
                return '', '', start
            result['background'] = end['background']
        else:
            bg_index = 99
            del result['background']
        return '\x03%02i,%02i' % (fg_index, bg_index), ',', result
    else:
        return '', '', start
Exemplo n.º 31
0
def drop_nicklist(paned, event):
    width = paned.get_allocated_width()
    pos = paned.get_position()

    double_click, nicklist_pos = paned._moving

    if double_click:
        # if we're "hidden", then we want to unhide
        if width - pos <= 10:
            # get the normal nicklist width
            conf_nicklist = conf.get("ui-gtk/nicklist-width", 200)

            # if the normal nicklist width is "hidden", then ignore it
            if conf_nicklist <= 10:
                paned.set_position(width - 200)
            else:
                paned.set_position(width - conf_nicklist)

        # else we hide
        else:
            paned.set_position(width)

    else:
        if pos != nicklist_pos:
            conf["ui-gtk/nicklist-width"] = width - pos - 6
Exemplo n.º 32
0
def onClose(e):
    nwindows = list(windows.get_with(core.manager, network=e.window.network))

    if isinstance(e.window, windows.ChannelWindow):
        cwindows = list(
            windows.get_with(core.manager,
                             network=e.window.network,
                             wclass=windows.ChannelWindow))

        #if we only have one window for the network, don't bother to part as
        # we'll soon be quitting anyway
        if len(nwindows) != 1 and irc_script.ischan(e.window.network,
                                                    e.window.id):
            e.window.network.part(e.window.id)

    if len(nwindows) == 1:
        core.events.trigger("CloseNetwork",
                            window=e.window,
                            network=e.window.network)

    elif isinstance(e.window, windows.StatusWindow) and conf.get('status'):
        core.events.trigger("CloseNetwork",
                            window=e.window,
                            network=e.window.network)
        for window in nwindows:
            if window != e.window:
                window.close()

    if len(core.manager) == 1:
        windows.new(windows.StatusWindow, irc.Network(), "status", core)
Exemplo n.º 33
0
	def group_exists(self,groupname):
		# check if the group exists already
		res = self.l.search(conf.get('LDAPSERVER','basedn'),\
		                   ldap.SCOPE_SUBTREE,'(& (cn=%s)(objectclass=posixgroup))'%groupname,['cn'])
		sres = self.l.result(res,0)
		if sres[1]==[]:
			return False
		return True
Exemplo n.º 34
0
def onSocketConnect(e):
    timeout = conf.get("server_traffic_timeout", 120) * 1000
    e.network._message_timeout = False
    if timeout:
        e.network._message_timeout_source = ui.register_timer(
            timeout, check_timeout, e.network)
    else:
        e.network._message_timeout_source = None
Exemplo n.º 35
0
def onHighlight(e):
    lowertext = e.text.lower()
    for word in conf.get('highlight_words', []) + [e.network.me] + e.network.nicks:
        lowerword = word.lower()
        pos = lowertext.find(lowerword, 0)
        while pos != -1:
            e.Highlight.append((pos, pos+len(word)))
            pos = lowertext.find(lowerword, pos+1)
Exemplo n.º 36
0
def generate_invoice_request(amount: float, memo: str = None):

    invoice = lnd.generate_invoice(amount, memo, conf.get('INVOICE_TIMEOUT'))

    if invoice is not None:
        return json.dumps(invoice)
    else:
        abort(500, 'Unable to generate a new invoice')
Exemplo n.º 37
0
def check_timeout(network):
    if network._message_timeout:
        network.raw("PING %s" % network.me)
        timeout = conf.get("server_death_timeout", 240)*1000
        network._message_timeout_source = ui.register_timer(timeout, check_death_timeout, network)
        return False
    else:
        network._message_timeout = True
        return True # call this function again
Exemplo n.º 38
0
def onHighlight(e):
    lowertext = e.text.lower()
    for word in conf.get('highlight_words', []) + \
            [e.network.me] + e.network.nicks:
        lowerword = word.lower()
        pos = lowertext.find(lowerword, 0)
        while pos != -1:
            e.Highlight.append((pos, pos + len(word)))
            pos = lowertext.find(lowerword, pos + 1)
Exemplo n.º 39
0
	def user_exists(self,uid):
		res = self.l.search(conf.get('LDAPSERVER','basedn'),\
		                   ldap.SCOPE_SUBTREE,'(& (uid=%s)(objectclass=posixaccount)(objectclass=person))'%uid,['dn'])
		
		sres = self.l.result(res,0)
		
		if sres[1]==[]:
			return False
		return True
Exemplo n.º 40
0
 def parser_config():
     """Rewrite tornado default parser_config_file.
     """
     for name in conf :
         value = conf.get(name)
         if name in options :
             options[name].set( value )
         else :
             define( name , default=value )
Exemplo n.º 41
0
 def quit(self, msg=None):
     if self.status:
         try:
             if msg == None:
                 msg = conf.get('quitmsg', "%s - %s" % (urk.long_version, urk.website))
             self.raw("QUIT :%s" % msg)
         except:
             pass
         self.disconnect()
Exemplo n.º 42
0
def redis_init():
    redis_conf = conf.get('redis', {})
    client = redis.Redis(
        host=redis_conf.get('host', 'redis-server'),
        port=redis_conf.get('port', 6379),
        db=redis_conf.get('database', 1),
        decode_responses=True
    )
    return client
Exemplo n.º 43
0
def after_request(response):
    if response.status == '200 OK':
        if response.headers.get('Content-Type', {}) == 'text/html; charset=utf-8':
            response.headers['Content-Type'] = 'application/json'

    response.headers['X-Server-Version'] = conf.get('VERSION')
    response.headers['X-Request-Id'] = request.headers.get('X-Request-ID', '')

    return response
Exemplo n.º 44
0
def check_timeout(network):
    if network._message_timeout:
        network.raw("PING %s" % network.me)
        timeout = conf.get("server_death_timeout", 240) * 1000
        network._message_timeout_source = ui.register_timer(
            timeout, check_death_timeout, network)
        return False
    else:
        network._message_timeout = True
        return True  # call this function again
Exemplo n.º 45
0
 def quit(self, msg=None):
     if self.status:
         try:
             if msg == None:
                 msg = conf.get(
                     'quitmsg',
                     "%s - %s" % (info.long_version, info.website))
             self.raw("QUIT :%s" % msg)
         except:
             pass
         self.disconnect()
Exemplo n.º 46
0
def influxdb_init():
    influxdb_conf = conf.get('influxdb', {})
    client = InfluxDBClient(
        host=influxdb_conf.get('host', 'influxdb-server'),
        port=influxdb_conf.get('port', 8086),
        username=influxdb_conf.get('username', ''),
        password=influxdb_conf.get('password', ''),
        database=influxdb_conf.get('database', 'telegraf'),
        gzip=True
    )
    return client
Exemplo n.º 47
0
def get_mirc_color(number):
    if number == '99':
        return None

    number = int(number) & 15

    confcolors = conf.get('colors', colors)
    try:
        return confcolors[number]
    except:
        # someone edited their colors wrongly
        return colors[number]
Exemplo n.º 48
0
def check_death_timeout(network):
    if network._message_timeout:
        network.raw("QUIT :Server missing, presumed dead")
        network.disconnect(
            error="The server seems to have stopped talking to us")
    else:
        network._message_timeout = False
        timeout = conf.get("server_traffic_timeout", 120) * 1000
        if timeout:
            network._message_timeout_source = ui.register_timer(
                timeout, check_timeout, network)
        else:
            network._message_timeout_source = None
Exemplo n.º 49
0
    def __init__(self, core):
        gtk.VBox.__init__(self)

        # threading stuff
        gtk.gdk.threads_init()
        self.core = core
        self.events = core.events
        self.tabs = Notebook()
        self.tabs.set_property("tab-pos",
                               conf.get("ui-gtk/tab-pos", gtk.POS_BOTTOM))

        self.tabs.set_scrollable(True)
        self.tabs.set_property("can-focus", False)
        self.pack_end(self.tabs)
Exemplo n.º 50
0
    def __init__(self, core):
        Gtk.VBox.__init__(self)

        # threading stuff
        Gdk.threads_init()
        self.core = core
        self.events = core.events
        self.tabs = Notebook()
        self.tabs.set_property(
            "tab-pos", conf.get("ui-Gtk/tab-pos", Gtk.PositionType.BOTTOM))

        self.tabs.set_scrollable(True)
        self.tabs.set_property("can-focus", False)
        self.pack_end(self.tabs, False, True, 0)
Exemplo n.º 51
0
def onCommandAlias(e):
    if e.args and 'r' in e.switches:
        name = e.args[0].lower()
        command = aliases[name]
        del aliases[name]
        conf['aliases'] = aliases
        e.window.write("* Deleted alias %s%s (was %s)" %
                       (conf.get('command-prefix', '/'), name, command))
        core.events.load(__name__, reloading=True)
    elif 'l' in e.switches:
        e.window.write("* Current aliases:")
        for i in aliases:
            e.window.write("*  %s%s: %s" %
                           (conf.get('command-prefix', '/'), i, aliases[i]))
    elif len(e.args) >= 2:
        name = e.args[0].lower()
        command = ' '.join(e.args[1:])
        aliases[name] = command
        conf['aliases'] = aliases
        e.window.write("* Created an alias %s%s to %s" %
                       (conf.get('command-prefix', '/'), name, command))
        core.events.reload(__name__)
    elif len(e.args) == 1:
        name = e.args[0].lower()
        if name in aliases:
            e.window.write(
                "* %s%s is an alias to %s" %
                (conf.get('command-prefix', '/'), name, aliases[name]))
        else:
            e.window.write("* There is no alias %s%s" %
                           (conf.get('command-prefix', '/'), name))
    else:
        e.window.write("""Usage:
 /alias \x02name\x02 \x02expression\x02 to create or replace an alias
 /alias \x02name\x02 to look at an alias
 /alias -r \x02name\x02 to remove an alias
 /alias -l to see a list of aliases""")
Exemplo n.º 52
0
    def __init__(self,
                 core,
                 activity,
                 server="irc.freenode.net",
                 port=8001,
                 nicks=[],
                 username="",
                 fullname="",
                 name=None,
                 **kwargs):
        self.core = core
        self.manager = core.manager
        self.server = server
        self.port = port
        self.events = core.events
        self.activity = activity

        self.name = name or server

        self.nicks = nicks or default_nicks()
        self.me = self.nicks[0]

        self.username = username or "urk"
        self.fullname = fullname or conf.get("fullname", self.username)
        self.password = ''

        self.isupport = {
            'NETWORK': server,
            'PREFIX': '(ohv)@%+',
            'CHANMODES': 'b,k,l,imnpstr',
        }
        self.prefixes = {
            'o': '@',
            'h': '%',
            'v': '+',
            '@': 'o',
            '%': 'h',
            '+': 'v'
        }

        self.status = DISCONNECTED
        self.failedhosts = []  # hosts we've tried and failed to connect to
        self.channel_prefixes = '&#+$'  # from rfc2812

        self.on_channels = set()
        self.requested_joins = set()
        self.requested_parts = set()

        self.buffer = ''
Exemplo n.º 53
0
def demux_map(dataset):
    print(dataset)
    csv_reference_file = conf.get('celery').get('csv_reference_file')
    csv_output_path = conf.get('celery').get('csv_output_path')
    csv_guppy_barcoding_threads = conf.get('celery').get('csv_guppy_barcoding_threads')
    reference_file = 'reference_file=%s' % csv_reference_file
    for data in dataset:
        for value in data.get('values'):
            fields = dict(zip(data.get('columns'), value))
            filename = os.path.basename(fields.get('path'))
            os.chdir('/tmp')
            command = [
                'snakemake',
                '--snakefile /opt/scripts/demux_map/Snakefile',
                '--configfile /opt/scripts/demux_map/config.yaml',
                '--cores 2',
                '--config',
                'input_fastq=%s/%s' % (data.get('tags').get('dir'), filename),
                'output_path=%s' % os.path.join(csv_output_path, data.get('tags').get('cell')),
                reference_file,
                'guppy_barcoding_threads=%s' % csv_guppy_barcoding_threads
            ]
            if not os.system(' '.join(command)) == 0:
                sys.exit(1)
Exemplo n.º 54
0
def onConnect(e):
    network_info = conf.get('networks', {}).get(e.network.name, {})

    for command in network_info.get('perform', []):
        while command.startswith(COMMAND_PREFIX):
            command = command[len(COMMAND_PREFIX):]
        core.events.run(command, e.window, e.network)

    tojoin = ','.join(network_info.get('join', []))
    if tojoin:
        core.events.run('join -n %s' % tojoin, e.window, e.network)

    if hasattr(e.network, 'temp_perform'):
        for command in e.network.temp_perform:
            core.events.run(command, e.window, e.network)
        del e.network.temp_perform
Exemplo n.º 55
0
def transform_color(start, end):
    if (start.get('foreground', 99) != end.get('foreground', 99)):
        confcolors = conf.get('colors', colors)
        result = start.copy()
        if 'foreground' in end:
            try:
                index = list(confcolors).index(end['foreground'].upper())
            except ValueError:
                return '', '', start
            result['foreground'] = end['foreground']
        else:
            index = 99
            del result['foreground']
        return '\x03%02i' % index, ',', result
    else:
        return '', '', start
Exemplo n.º 56
0
 def test_fastq_watch(self):
     test_fastq_file = 'test.fastq'
     data_dir = conf.get('ont').get('fastq_watch_path')
     cell = 'TEST-CELL'
     chip = 'TEST-CHIP'
     fastq_dir = os.path.join(data_dir, cell, chip, 'fastq_pass')
     if not os.path.exists(fastq_dir):
         os.makedirs(fastq_dir)
     tmp_fastq_file = os.path.join(fastq_dir, '%s.tmp' % test_fastq_file)
     fastq_file = tmp_fastq_file[:-4]
     shutil.copyfile(test_fastq_file, tmp_fastq_file)
     shutil.move(tmp_fastq_file, fastq_file)
     time.sleep(1)
     sql = "select * from fastq_watch where cell = '%s' and dir = '%s' and path = '%s'" % (
         cell, fastq_dir, fastq_file)
     res = influxdb_cli.query(sql)
     self.assertGreater(len(list(res.get_points())), 0)
Exemplo n.º 57
0
def add_autojoin(network, channel):
    if 'networks' not in conf:
        conf['networks'] = {}
    if network.name not in conf['networks']:
        conf['networks'][network.name] = {'server': network.server}
        conf['start_networks'] = conf.get('start_networks',
                                          []) + [network.name]
    if 'perform' in conf['networks'][network.name]:
        perform = conf['networks'][network.name]['perform']
    else:
        perform = conf['networks'][network.name]['perform'] = []

    for n, line in enumerate(perform):
        if line.startswith('join ') and ' ' not in line[5:]:
            perform[n] = "%s,%s" % (line, channel)
            break
    else:
        perform.append('join %s' % channel)
def handle():
    ont_conf = conf.get('ont')
    read_length_step = ont_conf.get('read_length_step')
    scan_iter = redis_cli.scan_iter(match='CELL:READ_LEN:*')
    measurement = 'reads_length_stats'
    influxdb_data = []
    for key in scan_iter:
        for k, v in redis_cli.hgetall(key).items():
            barcode, read_len = k.split('_')
            display_read_len = int(read_len) * read_length_step
            data = '%s,%s %s' % (
                measurement, 'cell=%s,barcode=%s,read_len=%s' % (
                    key[14:],
                    barcode,
                    '%s-%s' % ((read_length_step *
                                (int(read_len) - 1)) + 1, display_read_len),
                ), 'value=%s' % v)
            influxdb_data.append(data)
    influxdb_cli.write_points(points=influxdb_data, protocol='line')