Exemple #1
0
    def submitJobTemplate(self, testdir, metadata=None, validateOnly=False ):
        """
        Same as submitJob except that instead of using vParams and inputParams dictionaries
        you supply the name of a "job template" directory that contains 2 properties files,
        testParam.properties (which contains the vParams) and testInput.properties (which
        contains the inputParams).  The directory will also contain the input data files.
        For example, testParam.properties might look like: 
            toolId=CLUSTALW
            runtime_=.5
        and testInput.properties might look like:
            infile_=sample1_in.fasta
            usetree_=guidetree.dnd
        and the directory also contains files named sample1_in.fasta and guidetree.dnd.

        You can supply metadata via a dictionary argument, as with submitJob().
        """
        testdir = os.path.normpath(testdir) + os.sep
        fileParams = Props.Properties()
        with open(testdir + "input.properties") as infile:
            fileParams.load(infile)
        otherParams = Props.Properties()
        with open(testdir + "param.properties") as infile:
            otherParams.load(infile)

        for param in fileParams.propertyNames():
            pathname = fileParams.getProperty(param)
            if not os.path.isabs(pathname):
                pathname = os.path.join(testdir, os.path.basename(pathname))
            fileParams[param] = pathname 
        return self.submitJob(otherParams.getPropertyDictAsList(), fileParams.getPropertyDict(), metadata=metadata, validateOnly=validateOnly)
    def readProfile(self, profname):
        f = os.path.join(self.profiledir, profname + '.profile')
        p = pyjavaproperties.Properties()
        p.load(open(f))
        profile = dict()
        profile['filename'] = f
        profile['mtime'] = os.path.getmtime(f)
        for k,v in p.items():
            profile[k] = v
        for param in ('ssid', 'channel', 'ip', 'netmask', 'dns', 'ipgenerate'): ##Also validate ip, dns, bssid, channel?
            if param not in profile:
                self.log('Error in ' + f + ': missing or malformed ' + param + ' option') ## And raise some sort of error?
        if profile['ipgenerate'] in ('True', 'true', 'Yes', 'yes', '1'): # and not profile['randomip']
            self.log('Randomly generating static ip with base ' + profile['ip'] + ' and subnet ' + profile['netmask'])
            profile['ip'] = self._generate_ip(profile['ip'], profile['netmask'], self.getInterface())
            self.updateProfile(profname, {'ipgenerate': 'false', 'ip': profile['ip']})
        if not 'bssid' in profile: #Include note in default config file that bssid parameter is allowed, but should almost never be used
            self.log('Generating BSSID from hash of ssid and channel')
            bssid = hashlib.new('md5', profile['ssid']).hexdigest()[:8].upper() + '%02d' %int(int(profile['channel'])/10) + '%02d' %int(int(profile['channel'])%10)
            profile['bssid'] = ':'.join(a+b for a,b in zip(bssid[::2], bssid[1::2]))

        conf = os.path.join(re.sub('(.*)\profiles.d.*', r'\1olsrd.d', self.profiledir), profname + '.conf') #Unify this syntax by making profiledir just /etc/commotion?
        if os.path.exists(conf):
            self.log('profile has custom olsrd.conf: "' + conf + '"')
            profile['conf'] = conf
        else:
            self.log('using built in olsrd.conf: "' + self.olsrdconf + '"')
            profile['conf'] = self.olsrdconf
        return profile
Exemple #3
0
 def __init__(self):
     self.props = Props.Properties()
     confFile = "pycipres.conf"
     try:
         with open(confFile) as infile:
             self.props.load(infile)
     except IOError as e:
         raise
def dump_impl(data, config_fp):
    """TODO: How to encode nested dicts?
    """
    p = pyjavaproperties.Properties()
    for k, v in iteritems(data):
        p.setProperty(k, v)

    p.store(config_fp)
Exemple #5
0
 def setUp(self):
     p = pyjavaproperties.Properties()
     p.load(open('test-client.properties'))
     self.orcid_props = p
     self.client_id = self.orcid_props['memberClientId']
     self.client_secret = self.orcid_props['memberClientSecret']
     self.orcid_id = self.orcid_props['orcidId']
     self.token = self.orcid_generate_member_token(self.client_id,
                                                   self.client_secret,
                                                   'webhook')
 def get_profiles(self):
     '''get all the available mesh profiles and return as a list of tuples'''
     profiles = []
     for f in glob.glob('/etc/nm-dispatcher-olsrd/*.profile'):
         p = pyjavaproperties.Properties()
         p.load(open(f))
         bssid = p['bssid'].upper()
         channel = int(p['channel'])
         profiles.append(tuple([p['ssid'], bssid, channel]))
     return tuple(profiles)
Exemple #7
0
 def setUp(self):
     p = pyjavaproperties.Properties()
     p.load(open('test.properties'))
     self.orcid_props = p
     self.orcid_id = self.orcid_props['orcidId']
     self.client_id = self.orcid_props['memberClientId']
     self.client_secret = self.orcid_props['memberClientSecret']
     self.code = self.orcid_props['api2PostUpdateCode']
     self.token, self.refresh = self.orcid_exchange_auth_token(
         self.client_id, self.client_secret, self.code)
    def load_impl(cls, config_fp, **kwargs):
        """
        :param config_fp:  Config file object
        :param kwargs: backend-specific optional keyword parameters :: dict

        :return: dict object holding config parameters
        """
        p = pyjavaproperties.Properties()
        p.load(config_fp)

        return p.getPropertyDict()
Exemple #9
0
def pyjavaproperties_store(fp, props):
    import pyjavaproperties

    p = pyjavaproperties.Properties()
    for k, v in props.items():
        p[k] = v

    tmp = tempfile.NamedTemporaryFile(delete=False)
    try:
        p.store(tmp)
        with open(tmp.name, 'rb') as tmpfp:
            fp.write(tmpfp.read())
    finally:
        os.remove(tmp.name)
Exemple #10
0
    def write(keydict, savedir, password=None):
        '''given a keydict, generate a chatsecure file in the savedir'''
        p = pyjavaproperties.Properties()
        for name, key in keydict.items():
            # only include XMPP keys, since ChatSecure only supports XMPP
            # accounts, so we avoid spreading private keys around
            if key['protocol'] == 'prpl-jabber' or key[
                    'protocol'] == 'prpl-bonjour':
                if 'y' in key:
                    p.setProperty(key['name'] + '.publicKey',
                                  otrapps.util.ExportDsaX509(key))
                if 'x' in key:
                    if not password:
                        h = hashlib.sha256()
                        h.update(os.urandom(16))  # salt
                        h.update(bytes(key['x']))
                        password = h.digest().encode('base64')
                    p.setProperty(key['name'] + '.privateKey',
                                  otrapps.util.ExportDsaPkcs8(key))
            if 'fingerprint' in key:
                p.setProperty(key['name'] + '.fingerprint', key['fingerprint'])
            if 'verification' in key and key['verification'] != None:
                p.setProperty(
                    key['name'] + '.' + key['fingerprint'].lower() +
                    '.publicKey.verified', 'true')
        fd, filename = tempfile.mkstemp()
        f = os.fdopen(fd, 'w')
        p.store(f)

        # if there is no password, then one has not been set, or there
        # are not private keys included in the file, so its a lower
        # risk file. Encryption only needs to protect the meta data,
        # not the private keys.  Therefore, its not as bad to generate
        # a "random" password here
        if not password:
            password = os.urandom(32).encode('base64')

        # create passphrase file from the first private key
        cmd = [
            'openssl', 'aes-256-cbc', '-pass', 'stdin', '-in', filename,
            '-out',
            os.path.join(savedir, 'otr_keystore.ofcaes')
        ]
        p = subprocess.Popen(cmd,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
        ChatSecureProperties.password = password
        print((p.communicate(password)))
Exemple #11
0
 def parse(filename):
     '''parse the given file into the standard keydict'''
     # the parsing and generation is done in separate passes so that
     # multiple properties are combined into a single keydict per account,
     # containing all of the fields
     p = pyjavaproperties.Properties()
     p.load(open(filename))
     parsed = []
     for item in p.items():
         propkey = item[0]
         if propkey.endswith('.publicKey'):
             id = '.'.join(propkey.split('.')[0:-1])
             parsed.append(('public-key', id, item[1]))
         elif propkey.endswith('.publicKey.verified'):
             keylist = propkey.split('.')
             fingerprint = keylist[-3]
             id = '.'.join(keylist[0:-3])
             parsed.append(('verified', id, fingerprint))
         elif propkey.endswith('.privateKey'):
             id = '.'.join(propkey.split('.')[0:-1])
             parsed.append(('private-key', id, item[1]))
     # create blank keys for all IDs
     keydict = dict()
     for keydata in parsed:
         name = keydata[1]
         if not name in keydict:
             keydict[name] = dict()
             keydict[name]['name'] = name
             keydict[name]['protocol'] = 'prpl-jabber'
         if keydata[0] == 'private-key':
             cleaned = keydata[2].replace('\\n', '')
             numdict = otrapps.util.ParsePkcs8(cleaned)
             for num in ('g', 'p', 'q', 'x'):
                 keydict[name][num] = numdict[num]
         elif keydata[0] == 'verified':
             keydict[name]['verification'] = 'verified'
             fingerprint = keydata[2].lower()
             otrapps.util.check_and_set(keydict[name], 'fingerprint',
                                        fingerprint)
         elif keydata[0] == 'public-key':
             cleaned = keydata[2].replace('\\n', '')
             numdict = otrapps.util.ParseX509(cleaned)
             for num in ('y', 'g', 'p', 'q'):
                 keydict[name][num] = numdict[num]
             fingerprint = otrapps.util.fingerprint(
                 (numdict['y'], numdict['g'], numdict['p'], numdict['q']))
             otrapps.util.check_and_set(keydict[name], 'fingerprint',
                                        fingerprint)
     return keydict
Exemple #12
0
def pyjavaproperties_load(data):
    import pyjavaproperties

    p = pyjavaproperties.Properties()

    tmp = tempfile.NamedTemporaryFile(delete=False)
    try:
        with tmp:
            tmp.write(data)
        with open(tmp.name) as fp:
            p.load(fp)
    finally:
        os.remove(tmp.name)

    return p.getPropertyDict()
Exemple #13
0
#!/usr/bin/python

import pyjavaproperties
import imp

errors = imp.load_source('errors', '../../otrapps/errors.py')
util = imp.load_source('util', '../../otrapps/util.py')

filename = 'dsa-key.properties'
p = pyjavaproperties.Properties()
p.load(open(filename))
for item in p.items():
    if item[0] == 'privateKey':
        privdict = util.ParsePkcs8(item[1])
        print 'privdict: ',
        print privdict
    elif item[0] == 'publicKey':
        pubdict = util.ParseX509(item[1])
        print 'pubdict: ',
        print pubdict
def load_config():
    global config
    if not config:
        config = pyjavaproperties.Properties()
        with open(PROP_FILE) as file:
            config.load(file)
Exemple #15
0
 def __loadParamProperties(self):
     op = Props.Properties()
     with open(self.testdir + "testParam.properties") as infile:
         op.load(infile)
     return op
Exemple #16
0
 def __loadFileProperties(self):
     fp = Props.Properties()
     with open(self.testdir + "testInput.properties") as infile:
         fp.load(infile)
     return fp