Exemple #1
0
def main(ifile):
    logging.info("Using property file %s", ifile)
    with open(ifile) as fp:
        properties = jprops.load_properties(fp, collections.OrderedDict)
        con = psycopg2.connect(
            host=properties["redshift.dbhost"],
            port=properties["redshift.port"],
            user=properties["redshift.username"],
            password=properties["redshift.password"],
            database=properties["redshift.db"],
        )
        logging.info(
            "Connecting to DB using %s %s %s %s",
            properties["redshift.dbhost"],
            properties["redshift.port"],
            properties["redshift.username"],
            properties["redshift.db"],
        )
        con.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
        cur = con.cursor()
        tables = properties["redshift.tables"].split(",")
        for table in tables:
            logging.info("vacuuming  on %s" % table)
            cur.execute("vacuum delete only %s;" % table)
        cur.close()
Exemple #2
0
def modify_properties_file(fold):
    with open(CARSKIT_ORIGINAL_CONF_FILE) as read_file:
        properties = jprops.load_properties(read_file, collections.OrderedDict)

    recommender = Constants.CARSKIT_RECOMMENDERS
    ratings_fold_folder = CARSKIT_RATINGS_FOLD_FOLDER % fold

    if not os.path.exists(ratings_fold_folder):
        os.makedirs(ratings_fold_folder)

    modified_file = CARSKIT_MODIFIED_CONF_FILE % (fold, recommender)
    properties['recommender'] = recommender
    properties['dataset.ratings.lins'] = \
        ratings_fold_folder + 'carskit_train.csv'
    test_file = ratings_fold_folder + 'carskit_test.csv'
    properties['evaluation.setup'] = \
        'test-set -f %s --rand-seed 1 --test-view all' % test_file

    records = ETLUtils.load_json_file(
        Constants.RECSYS_CONTEXTUAL_PROCESSED_RECORDS_FILE)
    num_items = \
        len(extractor.get_groupby_list(records, Constants.ITEM_ID_FIELD))
    extra_items = num_items
    # extra_items = 10
    if Constants.CARSKIT_ITEM_RANKING:
        properties['item.ranking'] = 'on -topN %d' % extra_items
    else:
        properties['item.ranking'] = 'off'

    with open(modified_file, 'w') as write_file:
        jprops.store_properties(write_file, properties)
Exemple #3
0
 def _process_zip(self, strict):
     """
     Processes the contents of an AIA file into Python objects for further operation.
     """
     self.assets = []
     for name in self.zipfile.namelist():
         if name.startswith('assets/'):
             self.assets.append(AIAAsset(self, name))
             # TODO(ewpatton): Need to load extension JSON to extend language model
         elif name.startswith('src/'):
             if name.endswith('.scm'):
                 name = name[:-4]
                 form = self.zipfile.open('%s.scm' % name, 'r')
                 try:
                     blocks = self.zipfile.open('%s.bky' % name, 'r')
                 except KeyError as e:
                     if strict:
                         raise e
                     else:
                         blocks = None  # older aia without a bky file
                 screen = Screen(form=form, blocks=blocks)
                 self._screens[screen.name] = screen
         elif name.endswith('project.properties'):
             with self.zipfile.open(name) as prop_file:
                 self.properties = jprops.load_properties(prop_file)
         else:
             log.warning('Ignoring file in AIA: %s' % name)
Exemple #4
0
    def __init__(self):
        try:
            self.robohome = os.environ['ROBOHOME']
        except KeyError:
            print("Error in installation. $ROBOHOME does not exist")
            raise
        self.confdir = os.path.join(self.robohome, "conf")
        self.logdir = os.path.join(self.robohome, "log")
        self.imagedir = os.path.join(self.robohome, "img")
        self.sysprops = os.path.join(self.confdir, "robot.properties")
        f = 0
        try:
            f = open(self.sysprops, 'rb')
        except FileNotFoundError:
            self.props = {'home_lat': '59.1234', 'home_lon': '5.5678'}

            f = open(self.sysprops, 'wb')
            jprops.store_properties(f, self.props)
            f.close()
            f = open(self.sysprops, 'rb')

        self.props = jprops.load_properties(f)
        f.close()
        self.refresh()
        self.conf = self.confdir
Exemple #5
0
def get_remote_path(build_result_dir: str) -> str:
    # Sometimes one of the properties files is bad (empty or too short). In those cases try the other one before giving
    # up
    start_prop_file = os.path.join(
        build_result_dir, '.teamcity/properties/build.start.properties.gz')
    finish_prop_file = os.path.join(
        build_result_dir, '.teamcity/properties/build.finish.properties.gz')
    minimum_file_size_bytes = 100  # Consider files that are smaller than this invalid
    if os.path.isfile(start_prop_file) and os.path.getsize(start_prop_file) > minimum_file_size_bytes:
        properties_file = start_prop_file
    elif os.path.isfile(finish_prop_file) and os.path.getsize(finish_prop_file) > minimum_file_size_bytes:
        properties_file = finish_prop_file
    else:
        raise BadPropertiesFiles(
            "No sane looking properties file found in {}".format(build_result_dir))

    with gzip.open(properties_file, mode='rt', encoding="utf8") as fh:
        all_parameters = jprops.load_properties(fh)

        build_number = all_parameters['teamcity.build.id']
        build_id = all_parameters['system.teamcity.buildType.id']
        project_id = all_parameters['teamcity.project.id']

    return '{project_id}/{build_id}/{build_number}/'.format(project_id=project_id, build_id=build_id,
                                                            build_number=build_number)
Exemple #6
0
 def _process_dir(self, strict):
     """
     Processes the contents of a directory as if it were an AIA file and converts the content into Python objects
     for further operation.
     """
     self.assets = []
     asset_path = join(self.filename, 'assets')
     src_path = join(self.filename, 'src')
     for name in self._listfiles():
         if name.startswith(asset_path):
             self.assets.append(AIAAsset(None, name))
             # TODO(ewpatton): Need to load extension JSON to extend language model
         elif name.startswith(src_path) or name.endswith(
                 '.scm') or name.endswith('.bky'):
             if name.endswith('.scm'):
                 name = name[:-4]
                 if strict and not os.path.exists('%s.bky' % name):
                     raise IOError(
                         'Did not find expected blocks file %s.bky' % name)
                 bky_handle = open('%s.bky' % name) if os.path.exists(
                     '%s.bky' % name) else StringIO('<xml/>')
                 with open('%s.scm' % name,
                           'r') as form, bky_handle as blocks:
                     screen = Screen(form=form, blocks=blocks)
                     self._screens[screen.name] = screen
         elif name.endswith('project.properties'):
             with open(name, 'r') as prop_file:
                 self.properties = jprops.load_properties(prop_file)
         else:
             log.warning('Ignoring file in directory: %s' % name)
Exemple #7
0
def test_file_modes(tmpdir, opener, encoding, file_data, mode, newline):
  # check common combinations of various methods of opening files with different
  # encodings and line-endings

  if encoding is None:
    mode += 'b'
  expected_props = {u'a': u'\u0100'}

  if newline:
    file_data = file_data.replace(b'\n', newline.encode('ascii'))

  open_path = lambda path: opener(
    str(path),
    mode,
    encoding=encoding,
    newline=newline,
  )

  if 'r' in mode:
    read_path = tmpdir.join('reading.properties')
    read_path.write_binary(file_data)
    with open_path(read_path) as fp:
      actual_props = jprops.load_properties(fp)
    assert actual_props == expected_props

  else:
    write_path = tmpdir.join('writing.properties')
    with open_path(write_path) as fp:
      jprops.store_properties(fp, expected_props, timestamp=False)
    actual_data = write_path.read_binary()
    assert actual_data == file_data
Exemple #8
0
def read_properties_file(filename, encoding="utf-8"):
    with codecs.open(filename, encoding=encoding) as fp:
        if filename.endswith(EXT_PROPERTIES):
            properties = jprops.load_properties(fp)
        else:
            properties = json.load(fp)
    return properties
Exemple #9
0
def test_file_modes(tmpdir, opener, encoding, file_data, mode, newline):
    # check common combinations of various methods of opening files with different
    # encodings and line-endings

    if encoding is None:
        mode += 'b'
    expected_props = {u'a': u'\u0100'}

    if newline:
        file_data = file_data.replace(b'\n', newline.encode('ascii'))

    open_path = lambda path: opener(
        str(path),
        mode,
        encoding=encoding,
        newline=newline,
    )

    if 'r' in mode:
        read_path = tmpdir.join('reading.properties')
        read_path.write_binary(file_data)
        with open_path(read_path) as fp:
            actual_props = jprops.load_properties(fp)
        assert actual_props == expected_props

    else:
        write_path = tmpdir.join('writing.properties')
        with open_path(write_path) as fp:
            jprops.store_properties(fp, expected_props, timestamp=False)
        actual_data = write_path.read_binary()
        assert actual_data == file_data
Exemple #10
0
 def __init__(self):
     work_dir = os.path.join(os.path.dirname(__file__), '..', 'res', 'i18n')
     for lang in I18n.supportedLanguages:
         file = 'KortDB_'+lang+'.props'
         with open(os.path.join(work_dir, file)) as fp:
             props = jprops.load_properties(fp)
             I18n.languages[lang] = props
Exemple #11
0
def Property(key_file,properties_file):
   if not properties_file.startswith("/"):
      properties_file = "/var/www/goblin/current/etc/" + properties_file

   with open(properties_file) as fp:
      properties = jprops.load_properties(fp)
      return properties
def read_dict_from_properties(desired_type: Type[dict], file_object: TextIOBase,
                              logger: Logger, conversion_finder: ConversionFinder, **kwargs) -> Dict[str, Any]:
    """
    Helper method to read a dictionary from a .properties file (java-style) using jprops.
    Since jprops does not provide automatic handling for boolean and numbers, this tries to add the feature.

    :param file_object:
    :return:
    """

    # right now jprops relies on a byte stream. So we convert back our nicely decoded Text stream to a unicode
    # byte stream ! (urgh)
    class Unicoder:
        def __init__(self, file_object):
            self.f = file_object

        def __iter__(self):
            return self

        def __next__(self):
            line = self.f.__next__()
            return line.encode(encoding='utf-8')

    res = jprops.load_properties(Unicoder(file_object))

    # first automatic conversion of strings > numbers
    res = {key: try_parse_num_and_booleans(val) for key, val in res.items()}

    # further convert if required
    return ConversionFinder.convert_collection_values_according_to_pep(res, desired_type, conversion_finder, logger, 
                                                                       **kwargs)
Exemple #13
0
def jprops2bash(fh, key_transform=key_transform, value_transform=value_transform):
    props_dict = jprops.load_properties(fh, collections.OrderedDict)

    for key, value in props_dict.items():
        key = key_transform(key)
        value = value_transform(value)
        yield """export {key}='{value}'""".format(key=key, value=value)
Exemple #14
0
def read_properties_file(filename, encoding="utf-8"):
    with codecs.open(filename, encoding=encoding) as fp:
        if filename.endswith(EXT_PROPERTIES):
            properties = jprops.load_properties(fp)
        else:
            properties = json.load(fp)
    return properties
    def createUniqueFloodlightPropertiesFile(self):
        """
        Creates a unique properties file for the particular Floodlight instance.
        Each file is put in the 'properties' folder in the floodlight directory.
        Static class attributes keep track of the current port number to use.
        :return: None
        """

        # The path to the properties file to be copied and the name of the file
        old_path = Floodlight.fl_root_dir + 'src/main/resources/'
        old_file = 'floodlightdefault.properties'

        # The path where the new properties file will be located and the name of the file
        new_path = Floodlight.fl_root_dir + 'properties/'
        new_file = 'floodlight' + str(Floodlight.controller_number) + '.properties'

        # Set the instance attributes so that the instance can know where its associated properties file is
        self.properties_path = new_path
        self.properties_file = new_file

        # Check if the new path already exists. If not, then create it
        if not path.exists(new_path):
            makedirs(new_path)

        # Copy the old properties file to the new location with the new name
        shutil.copy(old_path + old_file,
                    new_path + new_file)

        # Open the new properties file and scan it for the ports that need to be changed
        with open(new_path + new_file) as fp:
            properties = jprops.load_properties(fp)

            http = [key for key, value in properties.items() if key.endswith('httpPort')][0]
            https = [key for key, value in properties.items() if key.endswith('httpsPort')][0]
            openflow = [key for key, value in properties.items() if key.endswith('openFlowPort')][0]
            syncmanager = [key for key, value in properties.items() if key.endswith('SyncManager.port')][0]

            properties[http] = str(Floodlight.http_port + 10)
            properties[https] = str(Floodlight.https_port + 10)
            properties[openflow] = str(Floodlight.openflow_port + 10)
            properties[syncmanager] = str(Floodlight.sync_manager_port + 10)

            # Update the class attributes so that everyone knows what ports are available now
            Floodlight.http_port += 10
            Floodlight.https_port += 10
            Floodlight.openflow_port += 10
            Floodlight.sync_manager_port += 10

            log.debug('Ports being used in controller ' + self.name + ' property file...\n')
            log.debug(http + ' = ' + properties[http] + '\n')
            log.debug(https + ' = ' + properties[https] + '\n')
            log.debug(openflow + ' = ' + properties[openflow] + '\n')
            log.debug(syncmanager + ' = ' + properties[syncmanager] + '\n')

        # Write the updated ports to the new properties file
        with open(new_path + new_file, 'w') as fp:
            # print 'Writing to file ' + new_file
            jprops.store_properties(fp, properties)
Exemple #16
0
 def __init__(self, rootDir, locations=None):
   allProperties = []
   if locations is not None:
     for location in locations:
       absLoc = os.path.join(rootDir, location)
       if os.path.isfile(absLoc):
         with open(absLoc, 'rb') as file:
           allProperties.append(jprops.load_properties(file))
   self.allProperties = allProperties
Exemple #17
0
 def _properties_shared(self):
     """Return content of "shared-data/header.properties"""
     path = "shared-data/header.properties"
     if path in self.files:
         with self.arc.open(path, "r") as fd:
             props = jprops.load_properties(fd)
     else:
         props = {}
     return props
Exemple #18
0
def loadPropertiesFile(filename: str) -> dict:
    """
    load a java properties file as a dict.
    """
    import jprops
    rslt = None
    with open(filename, "rb") as f:
        rslt = jprops.load_properties(f)
    return rslt
Exemple #19
0
 def _from_properties_url(url) -> dict:
     try:
         session = requests.Session()
         response = session.get(url)
         props = jprops.load_properties(io.StringIO(response.text))
         session.close()
         return props
     except Exception as e:
         sys.exit(123)
Exemple #20
0
 def __init__(self, rootDir, locations=None):
     allProperties = []
     if locations is not None:
         for location in locations:
             absLoc = os.path.join(rootDir, location)
             if os.path.isfile(absLoc):
                 with open(absLoc, 'rb') as file:
                     allProperties.append(jprops.load_properties(file))
     self.allProperties = allProperties
Exemple #21
0
 def __init__(self, propertiesPath):
     self.path = propertiesPath
     if os.path.exists(self.path) is True:
         with open(self.path) as fp:
             self.properties = jprops.load_properties(
                 fp, collections.OrderedDict)
         fp.close()
     else:
         return false
Exemple #22
0
def get_dburi_from_conf(configfile, propname = "rave.db.uri"):
    import jprops
    properties = {}
    try:
      with open(configfile) as fp:
        properties = jprops.load_properties(fp)
    except Exception as e:
      print(e.__str__())

    if propname in properties:
      return properties[propname]
    return None
def loadPropertiesFromFile(filename):
    """Returns a property dict loaded from a file"""
    if not isinstance(filename, str):
        raise TypeError('File name specified is not a string')
    if not filename:
        raise ValueError('filename specified cannot be empty')

    try:
        with open(filename) as fp:
            return jprops.load_properties(fp)
    except IOError as ex:
        raise IOError('Could not load properties file - %s' % ex)
Exemple #24
0
def create_db_from_conf(configfile=BDB_CONFIG_FILE, create_schema=True):
    properties = {}
    try:
        with open(configfile) as fp:
            properties = jprops.load_properties(fp)
    except Exception as e:
        print(e.__str__())

    propname = "rave.db.uri"
    if not propname in properties:
        propname = "baltrad.bdb.server.backend.sqla.uri"

    return create_db(properties[propname], create_schema)
Exemple #25
0
    def _load_configuration(self, configfile):
        '''loads the java property configuration file as defined by BDB_CONFIG_FILE
    If jprops not available in classpath or if the file isn't defined it will just
    be ignored.
    :return the properties as a dictionary
    '''
        properties = {}
        try:
            with open(configfile) as fp:
                properties = jprops.load_properties(fp)
        except:
            pass

        return properties
Exemple #26
0
def PoToProperties( pofilename, language, keep_comments, verbose = False ):
	if language is None:
		return

	pp = { }
	po = polib.pofile( pofilename )
	for e in po:
		for ( fname, key ) in e.occurrences:
			if fname not in pp:
				pp[ fname ] = OrderedDict( )
			# Use original text if translation was not finished
			pp[ fname ][ e.comment.strip( ) ] = e.msgstr if e.msgstr != "" else e.msgid
			#pp[ fname ][ e.comment.strip( ) ] = html_unescape( e.msgstr if e.msgstr != "" else e.msgid )

	for ( filename, msgs ) in pp.items( ):
		( root, ext ) = os.path.splitext( filename )
		fname = os.path.join( srcroot, root + "_" + language + ext )
		dname = os.path.dirname( fname )
		if not os.path.exists( dname ):
			os.makedirs( dname )

		master_filename = os.path.join( srcroot, filename )
		if keep_comments and os.path.exists( master_filename ):
			try: # check for file open
				# First, read master file with comments
				fr = open( master_filename, 'rU' )
				mpo = jprops.load_properties( fr, OrderedDict, True )
				fr.close( )

				fw = open( fname, 'w' )
				try: # check for writing contents
					for key in mpo:
						if key[:2] == '#@':
							fw.write( "\n" )
						elif key[:2] == '##':
							jprops.write_comment( fw, mpo[ key ][1:] )
						else:
							if key in msgs:
								jprops.write_property( fw, key, msgs[ key ] )
							else:
								jprops.write_property( fw, key, mpo[ key ] )
				except IOError, ( errno, msg ):
					print 'except: Cannot write to %s' % fname
					print 'errid: [%d] msg: [%s]' % (errno, msg)
				finally:
					fw.close( )
			except IOError, ( errno, msg ):
				print 'except: Cannot open "%s"' % fname
				print 'errid: [%d] msg: [%s]' % (errno, msg)
Exemple #27
0
def PoToProperties( pofilename, language, keep_comments, verbose = False ):
	if language is None:
		return

	pp = { }
	po = polib.pofile( pofilename )
	for e in po:
		for ( fname, key ) in e.occurrences:
			if fname not in pp:
				pp[ fname ] = OrderedDict( )
			# Use original text if translation was not finished
			pp[ fname ][ e.comment.strip( ) ] = e.msgstr if e.msgstr != "" else e.msgid
			#pp[ fname ][ e.comment.strip( ) ] = html_unescape( e.msgstr if e.msgstr != "" else e.msgid )

	for ( filename, msgs ) in pp.items( ):
		( root, ext ) = os.path.splitext( filename )
		fname = os.path.join( srcroot, root + "_" + language + ext )
		dname = os.path.dirname( fname )
		if not os.path.exists( dname ):
			os.makedirs( dname )

		master_filename = os.path.join( srcroot, filename )
		if keep_comments and os.path.exists( master_filename ):
			try: # check for file open
				# First, read master file with comments
				fr = open( master_filename, 'rU' )
				mpo = jprops.load_properties( fr, OrderedDict, True )
				fr.close( )

				fw = open( fname, 'w' )
				try: # check for writing contents
					for key in mpo:
						if key[:2] == '#@':
							fw.write( "\n" )
						elif key[:2] == '##':
							jprops.write_comment( fw, mpo[ key ][1:] )
						else:
							if key in msgs:
								jprops.write_property( fw, key, msgs[ key ] )
							else:
								jprops.write_property( fw, key, mpo[ key ] )
				except IOError, ( errno, msg ):
					print 'except: Cannot write to %s' % fname
					print 'errid: [%d] msg: [%s]' % (errno, msg)
				finally:
					fw.close( )
			except IOError, ( errno, msg ):
				print 'except: Cannot open "%s"' % fname
				print 'errid: [%d] msg: [%s]' % (errno, msg)
def getDependencies():
    with open(BASE_DIR + '/build.properties') as fp:
        properties = jprops.load_properties(fp)
        dependencies = ""
        depprojectnames = set()
        if properties.has_key('rebuild.list'):
            dependencies = properties['rebuild.list']
            dependencies = dependencies.split(',')
            dependencies = map(lambda x: x.strip(), dependencies)
            dependencies = filter(lambda x: len(x) > 0, dependencies)

            for dep in dependencies:
                depprojectnames.add(
                    getProjectNameFromDir(SHARED_PATH + "/" + dep))
        return depprojectnames
def writeDotProject():
    with open(BASE_DIR + '/build.properties') as fp:
        properties = jprops.load_properties(fp)
        if properties.has_key(
                'build_target') and properties['build_target'] == 'android':
            projectFile = 'defaultandroidproject'
        else:
            projectFile = 'defaultproject'
        fdefaultProject = open(
            SHARED_PATH + '/hmibuild/eclipse/' + projectFile, 'r')
        content = fdefaultProject.read()
        content = content.replace("$name$", getProjectName())
        fproject = open(BASE_DIR + '/.project', 'w')
        fproject.write(content)
        fproject.close()
Exemple #30
0
def get_media_properties(props_file=None):
    """Returns all properties found in the properties file as dictionary"""
    global PROPERTIES_FILE
    global DEFAULT_PROPERTIES_FILE
    global PROPERTIES_VALUES
    if props_file is None:
        props_file = DEFAULT_PROPERTIES_FILE
    if props_file == PROPERTIES_FILE and PROPERTIES_VALUES != {}:
        return PROPERTIES_VALUES
    PROPERTIES_FILE = props_file
    try:
        with open(props_file) as fp:
            PROPERTIES_VALUES = jprops.load_properties(fp)
    except FileNotFoundError:
        PROPERTIES_VALUES['binaries.ffmpeg'] = 'ffmpeg'
        PROPERTIES_VALUES['binaries.ffprobe'] = 'ffprobe'
    return PROPERTIES_VALUES
 def __init__(self, propertiesPath):
     self.path = propertiesPath
     if os.path.exists(self.path) is True:
         with open(self.path) as fp:
             self.properties = jprops.load_properties(
                 fp, collections.OrderedDict)
         fp.close()
     else:
         self.properties = {}
         self.set_property("allure.issues.id.pattern",
                           "\\b([A-Z]{1,3}[-][0-9]{1,4})\\b")
         self.set_property("allure.issues.tracker.pattern",
                           "http://jira.yourcompany.com/tests/%s")
         self.set_property("allure.tests.management.pattern",
                           "http://tms.yourcompany.com/tests/%s")
         self.set_property("allure.cli.logs.xml", "./allure-report")
         self.set_property("allure.cli.logs.xml.clear", "True")
def writeLaunchConfig(main):
    if len(main) == 0:
        return
    print("writing launch config for " + main)
    shortName = main.split('.')[-1]
    dir = BASE_DIR + '/.settings'
    if not os.path.exists(dir):
        os.makedirs(dir)

    jvmargs = ""
    with open(BASE_DIR + '/build.properties') as fp:
        root = ElementTree.Element("classpath")
        properties = jprops.load_properties(fp)
        if properties.has_key('run.jvmargs'):
            jvmargs = properties['run.jvmargs']

    root = ElementTree.Element("launchConfiguration")
    root.attrib["type"] = "org.eclipse.jdt.launching.localJavaApplication"
    listAttribute = ElementTree.SubElement(root, "listAttribute")
    listAttribute.attrib[
        "key"] = "org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"
    listEntry = ElementTree.SubElement(listAttribute, "listEntry")
    listEntry.attrib["value"] = '/' + getProjectName(
    ) + '/src/' + main.replace('.', '/') + '.java'

    listAttribute = ElementTree.SubElement(root, "listAttribute")
    listAttribute.attrib[
        "key"] = "org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"
    listEntry = ElementTree.SubElement(listAttribute, "listEntry")
    listEntry.attrib["value"] = "1"
    stringAttribute = ElementTree.SubElement(root, "stringAttribute")
    stringAttribute.attrib["key"] = "org.eclipse.jdt.launching.MAIN_TYPE"
    stringAttribute.attrib["value"] = main
    stringAttribute = ElementTree.SubElement(root, "stringAttribute")
    stringAttribute.attrib["key"] = "org.eclipse.jdt.launching.PROJECT_ATTR"
    stringAttribute.attrib["value"] = getProjectName()
    stringAttribute = ElementTree.SubElement(root, "stringAttribute")
    stringAttribute.attrib["key"] = "org.eclipse.jdt.launching.VM_ARGUMENTS"
    stringAttribute.attrib["value"] = jvmargs + ' -Djava.library.path=lib'

    with open(dir + '/' + shortName + '.launch', 'w') as fp:
        fp.write(prettify(root))
Exemple #33
0
 def read_config_file(self,config):
     """Reads config file or URL and parses it's content
         
         :Parameters:
         config: string
             File path or URL to config file
     """
     if not config:
         return
     fp = None
     if config.find('http') == 0:
         data = str(requests.get(config).text)
         fp = StringIO.StringIO(data)
     else:
         fp = open(config,'rb')
     if fp:
         props = jprops.load_properties(fp)
         fp.close()
         map(lambda x: x.strip(),props)
         return props
def compute_rouge(event):
    """
    Compute rouge-1 score for an event
    :param event: Name of the event
    :return:
    """
    summaries_path = Path(LOCAL_DATA_DIR_2, 'data', event, 'summaries')

    with open('rouge.properties', 'r+') as fp:
        props = jprops.load_properties(fp, collections.OrderedDict)
        ngrams = props.get('ngram')
        result_path = Path(LOCAL_DATA_DIR_2, 'data', event, 'summaries', 'result_rouge_ngram' + str(ngrams) + '.csv')
        props.pop('project.dir')
        props.pop('outputFile')
        props.update({'project.dir': str(summaries_path.absolute()), 'outputFile': str(result_path.absolute())})
        fp.seek(0)
        fp.truncate()
        jprops.store_properties(fp, props)

    subprocess.call(['java', '-jar', 'rouge2.0_0.2.jar', '-Drouge.prop=', 'rouge.properties'])
def getResources():
    with open(BASE_DIR + '/build.properties') as fp:
        properties = jprops.load_properties(fp)
        resources = ""
        if properties.has_key('resource.path'):
            resources = properties['resource.path']
        if properties.has_key('test.resource.path'):
            resources = resources + ';' + properties['test.resource.path']
        resources = resources.split(';')
        resources = map(lambda x: x.replace('${shared.resources}', SHARED_RES),
                        resources)
        resources = map(
            lambda x: x.replace('${asap.resources}', ASAPSHARED_RES),
            resources)
        resources = map(
            lambda x: x.replace('${shared.project.root}', SHARED_PATH),
            resources)
        resources = map(lambda x: x.strip(), resources)
        resources = filter(lambda x: len(x) > 0, resources)
        resources = set(resources)
        return resources
Exemple #36
0
def modify_properties_file(fold):
    with open(CARSKIT_ORIGINAL_CONF_FILE) as read_file:
        properties = jprops.load_properties(read_file, collections.OrderedDict)

    CARSKIT_CONF_FOLD_FOLDER = Constants.RIVAL_RATINGS_FOLD_FOLDER + 'carskit/'
    CARSKIT_MODIFIED_CONF_FILE = CARSKIT_CONF_FOLD_FOLDER + '%s.conf'
    recommender = Constants.CARSKIT_RECOMMENDERS
    carskit_conf_fold_folder = CARSKIT_CONF_FOLD_FOLDER % fold
    ratings_fold_folder = Constants.RIVAL_RATINGS_FOLD_FOLDER % fold
    prediction_type_map = {
        'user_test': 'rating',
        'test_items': 'rating',
        'rel_plus_n': 'ranking'
    }
    prediction_type = prediction_type_map[Constants.RIVAL_EVALUATION_STRATEGY]

    if not os.path.exists(carskit_conf_fold_folder):
        os.makedirs(carskit_conf_fold_folder)

    modified_file = CARSKIT_MODIFIED_CONF_FILE % (fold, recommender)
    properties['recommender'] = recommender
    train_file = ratings_fold_folder + 'carskit_train.csv'
    test_file = \
        ratings_fold_folder + 'carskit_predictions_%s.csv' % (prediction_type)
    properties['dataset.ratings.lins'] = train_file
    properties['evaluation.setup'] = \
        'test-set -f %s --rand-seed 1 --test-view all' % test_file
    properties['item.ranking'] = 'off'

    properties['output.setup'] =\
        '-folder %s -verbose on, off --to-file %s%s_summary.txt' % (
            ratings_fold_folder, ratings_fold_folder, recommender)

    params = process_carskit_parameters(Constants.CARSKIT_PARAMETERS)

    for key, value in params.items():
        properties[key] = value

    with open(modified_file, 'w') as write_file:
        jprops.store_properties(write_file, properties)
Exemple #37
0
def modify_properties_file(fold):
    with open(CARSKIT_ORIGINAL_CONF_FILE) as read_file:
        properties = jprops.load_properties(read_file, collections.OrderedDict)

    CARSKIT_CONF_FOLD_FOLDER = Constants.RIVAL_RATINGS_FOLD_FOLDER + 'carskit/'
    CARSKIT_MODIFIED_CONF_FILE = CARSKIT_CONF_FOLD_FOLDER + '%s.conf'
    recommender = Constants.CARSKIT_RECOMMENDERS
    carskit_conf_fold_folder = CARSKIT_CONF_FOLD_FOLDER % fold
    ratings_fold_folder = Constants.RIVAL_RATINGS_FOLD_FOLDER % fold
    prediction_type_map = {
        'user_test': 'rating',
        'test_items': 'rating',
        'rel_plus_n': 'ranking'
    }
    prediction_type = prediction_type_map[Constants.RIVAL_EVALUATION_STRATEGY]

    if not os.path.exists(carskit_conf_fold_folder):
        os.makedirs(carskit_conf_fold_folder)

    modified_file = CARSKIT_MODIFIED_CONF_FILE % (fold, recommender)
    properties['recommender'] = recommender
    train_file = ratings_fold_folder + 'carskit_train.csv'
    test_file = \
        ratings_fold_folder + 'carskit_predictions_%s.csv' % (prediction_type)
    properties['dataset.ratings.lins'] = train_file
    properties['evaluation.setup'] = \
        'test-set -f %s --rand-seed 1 --test-view all' % test_file
    properties['item.ranking'] = 'off'

    properties['output.setup'] =\
        '-folder %s -verbose on, off --to-file %s%s_summary.txt' % (
            ratings_fold_folder, ratings_fold_folder, recommender)

    params = process_carskit_parameters(Constants.CARSKIT_PARAMETERS)

    for key, value in params.items():
        properties[key] = value

    with open(modified_file, 'w') as write_file:
        jprops.store_properties(write_file, properties)
Exemple #38
0
        monster['environments'] = envListToAdd

    # create the output file
    with open(outFile, 'w') as outfile:
        json.dump(monsters, outfile)

    logging.info("Completed merge.")


# call main
if __name__ == '__main__':

    # load configuration properties
    propertyfile = sys.argv[1]

    if os.path.isfile(propertyfile) == False:
        raise Exception('Configuration File %s  does not exist.', propertyfile)

    with open(propertyfile) as F:
        props = jprops.load_properties(F, collections.OrderedDict)

        monstersSourceFile = props['monsters.file.path']
        envMappingSourceFile = props['monsters.by.environment.file.path']
        mergedOutputFile = props['merged.output.file.path']

    monsters = json.load(open(monstersSourceFile))
    environments = json.load(open(envMappingSourceFile))

    monsters = removeLicense(monsters)
    mergeMetadata(monsters, environments, mergedOutputFile)
# These properties are skipped, even if their values don't match the default
ignored_props = [
	'javax.net.ssl.trustStore',
	'fip.group.groupMapping',
	'fip.pairMapping',
	'fip.pairxsl',
	'fip.report.inputScreen.checker',
	'fip.weburl',
	'fip.appLocation'
]

properties_buffer = "fip.app.url={0}\n".format(app_url)

with open(fip_props_file) as fp:
	fip_props = jprops.load_properties(fp);
	broker = fip_props['com.foundationip.activemq.brokerURL']

	if broker:
		properties_buffer += "\ncom.foundationip.activemq.brokerURL={0}".format(broker)

with open(fip_default_props_file) as fp:
	default_properties = jprops.load_properties(fp);

	for default in sorted(default_properties):		
		tag = root.find('.//' + default)

		if tag != None and default not in ignored_props:
			# Get the actual and default values, strip whitespace and compare
			xml_value = (tag.text or "").strip()
			default_value = (default_properties[default] or "").strip()
Exemple #40
0
from flask import Flask
from flask import jsonify
from flask import render_template
from flask import request
import mysql.connector
import jprops

# Load our mainConfig.properties file for public use.
properties = jprops.load_properties(open('res/mainConfig.properties'))

app = Flask(__name__)


@app.route('/wins')
def wins():
    # Retrieve query parameters.
    db = int(request.args.get('bender'))
    start = int(request.args.get('start', 0))
    stack_size = int(request.args.get('stack_size', 10))
    end = int(request.args.get('end', start + (50)))

    # Split the DB property entry.
    dbs = str(properties.get('DB')).split(',')
    # Check that the 'bender' query param references a valid DB.
    if db >= len(dbs):
        raise ValueError('DB does not exist.')
    # Generate result set.
    result = condense_wins(dbs[db], stack_size, start, end)
    return jsonify(result=result,
                   count=len(result),
                   axe={
def loadPropertiesFromFileHandle(fh):
    """Returns a property dict loaded from a open file handle"""
    return jprops.load_properties(fh)
Exemple #42
0
def jprops_load(data):
  return jprops.load_properties(io.BytesIO(data))
from pkg_resources import resource_filename
import os
import jprops
import nose.tools as nt

from ezbake.configuration.EzConfiguration import EzConfiguration
from ezbake.configuration.loaders.PropertiesConfigurationLoader import PropertiesConfigurationLoader
from ezbake.configuration.loaders.DirectoryConfigurationLoader import DirectoryConfigurationLoader
from ezbake.configuration.loaders.OpenShiftConfigurationLoader import OpenShiftConfigurationLoader



conf = resource_filename('tests', 'config/ezbake-config.properties')
with open(conf) as fp:
    properties = jprops.load_properties(fp)


def testEZConfiguration():
    config = EzConfiguration(PropertiesConfigurationLoader(properties))
    nt.eq_(properties.get('application.name', ''),
           config.getProperties().get('application.name',''))


def testLoadFromPackage():
    config = EzConfiguration(DirectoryConfigurationLoader(__name__), PropertiesConfigurationLoader(properties), OpenShiftConfigurationLoader())
    nt.eq_(properties.get('application.name', ''),
           config.getProperties().get('application.name'))

def testLoadFromDefaults():
    #set os env
Exemple #44
0
def PotFromProperties( searchpath, language, verbose = False ):
	# Construct pot file
	pot = polib.POFile( )
	pot.metadata = {
		'Project-Id-Version': 'TMX Project 0.1a',
		'Report-Msgid-Bugs-To': '*****@*****.**',
		'POT-Creation-Date': datetime.datetime.utcnow( ).strftime("%Y-%m-%d %H:%M") + "+00:00",
		'PO-Revision-Date': 'YEAR-MO-DA HO:MI+ZONE',
		'Last-Translator': 'FULL NAME <EMAIL@ADDRESS>',
		'Language-Team': 'LANGUAGE <EMAIL@ADDRESS>',
		'MIME-Version': '1.0',
		'Content-Type': 'text/plain; charset=utf-8',
		'Content-Transfer-Encoding': '8bit',
	}

	found = False
	list = EnumPropertiesFiles( searchpath, verbose )
	for ( filename, ismaster ) in list:
		if not ismaster:
			continue

		found = True
		fr = open( filename, 'rU' )
		p = jprops.load_properties( fr, OrderedDict )
		fr.close( )

		count = 1
		for ( key, value ) in p.items( ):
			if value != "":
				fname = filename[len( srcroot )+1:]
				e = polib.POEntry(
					comment = key,
					msgctxt = fname + ':' + key,
					msgid = value,
					msgstr = value if language is None else '',
					#msgid = html_escape( value ),
					#msgstr = html_escape( value ) if language is None else '',
					occurrences = [( fname, count )]
				)
				pot.append( e )
				count = count + 1

	if not found:
		return( None )

	if language is not None:
		for ( filename, ismaster ) in list:
			if filename.find( '_' + language ) < 0:
				continue

			fr = open( filename, 'rU' )
			p = jprops.load_properties( fr )
			fr.close( )

			( root, ext ) = os.path.splitext( filename );
			master = root[len( srcroot )+1:-len(language)-1] + ext

			for ( key, value ) in p.items( ):
				e = pot.find( key, by='comment', msgctxt=master+':'+key )
				if e is not None:
					e.msgstr = value

	return( pot )
Exemple #45
0
def main():

    # -----------------------------------------------------------------
    # Variables

    # Constants
    INI_FILE_NAME = "info\data.ini"
    MSG_FILE_NME = "info\message.txt"
    MSGS_PER_LOGIN = 9

    msg_file_dir = os.getcwd()+'\\'+MSG_FILE_NME
    msgToSend = getMsgToSend(msg_file_dir)

    #print 'Vestule: '+msgToSend
    # Data from file
    ini_file_dir = os.getcwd()+'\\'+INI_FILE_NAME
    properties = {}
    with open(ini_file_dir) as fp:
        properties = jprops.load_properties(fp)
    print 'data.ini fails',properties

    # all emails
    loginEmails = getEmails(properties)
    print 'Tavi profili',loginEmails
    group = properties['group']
    emailCount = len(loginEmails)

    # vars for keeping track of current login, fan page, msgs sent
    page = 0
    lastPage = 0
    if RepresentsInt( properties['groupStart'] ): page = int(properties['groupStart'])
    else:
        print 'Nekorekts grupas lapas numurs ieks fails'
        sys.exit()

    lastPage = int(getLastFanPageNumber(group))
    print 'Grupas ['+group+'] sekotaju lapu skaits:',lastPage

    TEST = '1'
    if properties['test'] == '0':
        TEST = '0'
    print "test:",TEST

    loadImages = '0'
    if properties['loadImages'] == '1':
        loadImages = '1'

    timeout = 25
    if RepresentsInt( properties['timeout'] ): timeout = int(properties['timeout'])
    else:
        print 'Nekorekts timeout failaa'
        print 'Timeouts tiek uzstadits uz 25 minutem'

    print 'Timeouts:',timeout

    attachFile = properties['attachFile']
    attachFileName = properties['attachFileName']

    attachTime = 10
    if RepresentsInt( properties['attachTime'] ): attachTime = int(properties['attachTime'])
    else:
        print 'Nekorekta vertiba pie \'augsupladeshanas laika \''

    currentLoginProfile = 0
    currentUid = 0
    msgsSent = 0
    totalUsersVisited = 0
    lastUser = False
    isMsgSent = False
    isModalClose = True

    # get user ids from group page 
    uids = getUids(group, page)

    print 'Lietotaju celi lapaa',page,':',uids
    print 'To skaits:',len(uids)

    # End of variables
    # ------------------------------------------------------------------------
    # Sart browser
    browser = 0
    if properties['browser'] == 'Chrome':
        if loadImages == '0':
            chromeOptions = webdriver.ChromeOptions()
            prefs = {"profile.managed_default_content_settings.images":2}
            chromeOptions.add_experimental_option("prefs",prefs)
            browser = webdriver.Chrome(chrome_options=chromeOptions)
            print 'ImagesOff'
        else:
            browser = webdriver.Chrome()
            print 'ImagesOn'

    elif properties['browser'] == 'Firefox':
        firefoxProfile = FirefoxProfile()
        firefoxProfile.set_preference('permissions.default.image', 3)
        browser = webdriver.Firefox(firefoxProfile)
    else:
        print "Nepareiza parlukprogrammas opcija"
        sys.exit()
    # ------------------------------------------------------------------------

    while True: # main loop
        for email in loginEmails: # email loop

            if currentUid >= len(uids):
                page +=1 
                uids = getUids(group, page)
                currentUid = 0

            browser.get('http://www.draugiem.lv'+uids[currentUid])
            print 'LietotajaUid:',currentUid, uids[currentUid]
            
            print 'Ielogojas ar ['+email+']'
            loginDrlv(browser, email, properties[email])

            while True: # message loop
                print 'lappuse:', page
                if newMsg(browser):

                    if writeMsg(browser, msgToSend):
                        isModalClose = False
                        if attachFile == '1':
                            attachFileToMsg(browser,attachFileName)
                            sleep(attachTime)
                        if TEST == '0': 
                            sendMsg(browser)
                            sleep(3) # for modal refresh
                            if closeMsgSentModal(browser):
                                isModalClose = True

                        msgsSent += 1
                        isMsgSent = True
                        print "Nosutitas zinas ar tekoso loginu:",msgsSent

                else: 
                    isMsgSent = False

                if msgsSent >= MSGS_PER_LOGIN or lastUser: break

                currentUid += 1
                totalUsersVisited += 1

                if currentUid >= len(uids):
                    page +=1 
                    if page > lastPage:
                        print 'Sasniegts pedejais grupas sekotajs. Beigas'
                        lastUser = True
                        currentUid = 0
                        break
                    uids = getUids(group, page)
                    currentUid = 0

                browser.get('http://www.draugiem.lv'+uids[currentUid])
                print 'LietotajaUid:',currentUid, uids[currentUid]


            msgsSent = 0

            print 'Logina vestulu limits sasniegts'
            print 'Izlogojas no ['+email+']'

            if not isModalClose: 
                print 'Modal pec vestules izsutisana nav aizverts. Parlade lapu un izlogojas...'
                browser.get('http://www.draugiem.lv'+uids[0])

            logoutDrlv(browser)
            sleep(2)

            if lastUser:
                break

        if lastUser:
            print 'Beigas'
            break

        Timeout(timeout)
Exemple #46
0
 def read(self):
     with open(self.propsFileName) as fp:
         self.propsFile = jprops.load_properties(fp)
Exemple #47
0
def read_properties_file(filename, encoding="utf-8"):
    with codecs.open(filename, encoding=encoding) as fp:
        properties = jprops.load_properties(fp)
    return properties