[Python] I'd like to ask you how to export only certain parts of manifest.xml and save them as a single file.

Asked 2 years ago, Updated 2 years ago, 40 views

I'm going to ask you a question using Python I'm looking for a way to create a Python script that automatically saves the storage name of git repository as a single file among the contents included in the manifest.xml below, but I couldn't think of a proper way to ask this question.

First of all, assuming that the contents in the manifest.xml are as follows, I want to automatically create a single file by filtering only the storage names of all projects among the name= storage names after each path.

I've been thinking about two things 1) Use xml parsing to pull it out.(Difficult because it's high-tech)

Of the two types, shell script and python, I think it would be easier to implement through python, so I would like to export only the repository names of all git projects by turning the second method, loop statement.

<?xml version="1.0" encoding="UTF-8"?> <manifest>   <remote name="origin" fetch="ssh://[email protected]/" />   <default revision="master" remote="origin" />

  <project path="lib/plist-lib"
           name="keiji/AndroidPListLib.git" remote="origin" />

  <project path="lib/json-pull-parser"
           name="vvakame/JsonPullParser.git" remote="origin" />

  <project path="apps/twicca_megane_plugin"
           name="zaki50/TwiccaMeganePlugin.git" remote="origin" /> </manifest>

Thank you.

python git

2022-09-22 18:02

1 Answers

Python has modules for xml processing.

import xml.etree.ElementTree as eTree

xmlTree = eTree.parse('manifest.xml')
projects = xmlTree.findall('project')
with open('newFile.txt', 'wt') as f:
    f.writelines((project.get('name') + '\n' for project in projects))


2022-09-22 18:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.