def get_package_name(project_path):
    app_dir = os.path.join(project_path, 'app')
    android_manifest_file = fh.search_file(app_dir, 'AndroidManifest.xml')[0]
    android_manifest_file_xml = xh.read_xml_file(android_manifest_file)
    root_node = xh.get_root_node(android_manifest_file_xml)
    package_name = xh.get_node_att(root_node, 'package')
    return package_name
def build_strings_dict(strings_file_path):
    strings_xml = xh.read_xml_file(strings_file_path)
    strings_node = xh.find_all_nodes(xh.get_root_node(strings_xml), 'string')

    nodes_to_translate = []
    for node in strings_node:
        translatable_val = xh.get_node_att(node, 'translatable')
        if translatable_val is None or translatable_val == "true":
            nodes_to_translate.append(node)
    return nodes_to_translate
Example #3
0
def add_extension_nodes(xml_path, place_holder_map, root_node, xml):
    extension_mapper_path = xh.get_node_att(
        root_node, res.NODE_ROOT_ATT_EXTENSION_MAPPER_PATH)
    if extension_mapper_path:
        extension_mapper_path = tools.rel_path_to_abs(extension_mapper_path,
                                                      xml_path)
        extension_mapper_path = fill_place_holders(extension_mapper_path,
                                                   place_holder_map)
        extension_xml = xh.read_xml_file(extension_mapper_path)
        return xh.merge_xml1_with_xml2(extension_xml, xml)
    else:
        return xml
def manipulate_files_by_xml(xml_path, place_holder_map=None):
    """
    Will copy/delete files/directories defined by an xml map file.

    param xml_path: the path to your XML file
    place_holder_map: a map holding the place holders that appear in the xml file, with their respective definitions.
    The map could be like {'$dynamic_src': '/Users/home/my_dyn_src',
                       '$dynamic_dst': '/Users/home/my_dyn_dst'}
    """
    if place_holder_map is None:
        place_holder_map = {}
    xml = xh.read_xml_file(xml_path)
    file_manipulator.manipulate(xml_path, xml, place_holder_map)
def set_texts_by_xml(xml_path, place_holder_map=None):
    """
    Will copy/append text defined by an xml map file.

    NOTICE: It doesn't matter what the tag names of root/the text nodes or the new line.
    Just make sure you have the 'original' tags where they should be and that the attribute 'src' and 'dst' is satisfied for each sub node of the root.

    param xml_path: the path to your XML file
    place_holder_map: a map holding the place holders that appear in the xml file, with their respective definitions.
    The map could be like {'$dynamic_src': '/Users/home/my_dyn_src',
                       '$dynamic_dst': '/Users/home/my_dyn_dst'}
    """
    if place_holder_map is None:
        place_holder_map = {}
    xml = xh.read_xml_file(xml_path)

    text_manipulator.manipulate(xml_path, xml, place_holder_map)
Example #6
0
from os_xml_handler import xml_handler as xh

# groups_dir = '/Users/home/Desktop/work/Apps/groups'
# group_dir_list = fh.get_dir_content(groups_dir, True, False, True)
# print(group_dir_list)

xml1 = xh.read_xml_file('/Users/home/Desktop/bv/xml1.xml')
root = xh.get_root_node(xml1)
holder = xh.get_root_direct_child_nodes(xml1, 'holder')[0]
next_dhdren = xh.get_all_direct_child_nodes(holder, False)
print(next_dhdren)



# xml2 = xml_handler.read_xml_file('/Users/home/Desktop/bv/xml2.xml')
#
# xml3 = xml_handler.merge_xml1_with_xml2(xml1, xml2)
# xml_handler.save_xml_file(xml3, '/Users/home/Desktop/bv/xml3.xml')
#
# files = fh.search_files('/Users/home/Programming/android/coroutine/rwdc-coroutines-materials/starter/app/src/main/res', by_extension='.xml')
# content = fh.get_dir_content("/Users/home/Desktop/apps", False, True, False)
# print(files)

# print(content)