Kaydet (Commit) 9f03266f authored tarafından Suleyman Poyraz's avatar Suleyman Poyraz

çalışması için elimden geleni yaptım

üst acd88407
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
#
# Old author: Copyright (C) 2005 - 2011, Tubitak/UEKAE
#
# Copyright (C) 2016 - 2018, Suleyman POYRAZ (Zaryob) # Copyright (C) 2016 - 2018, Suleyman POYRAZ (Zaryob)
# #
# This program is free software; you can redistribute it and/or modify it under # This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free # the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option) # Software Foundation; either version 3 of the License, or (at your option)
# any later version. # any later version.
# #
# Please read the COPYING file. # Please read the COPYING file.
...@@ -17,7 +20,6 @@ _ = __trans.gettext ...@@ -17,7 +20,6 @@ _ = __trans.gettext
import os import os
import xml.dom.minidom as minidom import xml.dom.minidom as minidom
from xml.parsers.expat import ExpatError
import inary import inary
import inary.uri import inary.uri
...@@ -48,51 +50,45 @@ class RepoOrder: ...@@ -48,51 +50,45 @@ class RepoOrder:
def add(self, repo_name, repo_url, repo_type="remote"): def add(self, repo_name, repo_url, repo_type="remote"):
repo_doc = self._get_doc() repo_doc = self._get_doc()
try: repo_node = repo_doc.createElement("Repo")
#FIXME:Burada bir sakatlık çıkacak
#2018-03-12 dedim ama ben gunler oncesinden dedim
node = [x for x in repo_doc.childNodes if x.nodeType == x.ELEMENT_NODE and x.tagName == "Repo"][-1]
repo_node = repo_doc.appendChild(node.createElement("Repo"))
except Exception:
repo_node = repo_doc.appendChild(repo_doc.createElement("Repo"))
name_node = repo_node.createElement("Name") name_node = repo_node.createElement("Name")
name_node.appendChild(node.createTextNode(repo_name)) name_node.appendChild(repo_doc.createTextNode(repo_name))
repo_node.appendChild(name_node) repo_node.appendChild(name_node)
url_node = repo_node.createElement("Url") url_node = repo_node.createElement("Url")
url_node.appendChild(node.createTextNode(repo_url)) url_node.appendChild(repo_doc.createTextNode(repo_url))
repo_node.appendChild(url_node) repo_node.appendChild(url_node)
status_node = repo_node.createElement("Status") status_node = repo_node.createElement("Status")
status_node.appendChild(node.createTextNode("active")) status_node.appendChild(repo_doc.createTextNode("active"))
repo_node.appendChild(status_node) repo_node.appendChild(status_node)
media_node = repo_node.createElement("Media") media_node = repo_node.createElement("Media")
media_node.appendChild(node.createTextNode(repo_type)) media_node.appendChild(repo_doc.createTextNode(repo_type))
repo_node.appendChild(media_node) repo_node.appendChild(media_node)
self._update(repo_doc) self._update(repo_doc)
def set_status(self, repo_name, status): def set_status(self, repo_name, status):
repo_doc = self._get_doc() repo_doc = self._get_doc()
for r in repo_doc.childNodes:
for r in repo_doc.getElementsByTagName("Repo"): if r.nodeType == r.ELEMENT_NODE and r.tagName == "Repo":
if r.getElementsByTagName("Name")[0].firstChild.data == repo_name: if r.getElementsByTagName("Name")[0].firstChild.data == repo_name:
status_node = r.getElementsByTagName("Status")[0] status_node = r.getElementsByTagName("Status")[0]
print(dir(status_node))
if status_node: if status_node:
status_node.childNodes[0].data status_node.childNodes[0].nodeValue = status
status_node.insertData(status)
else: else:
status_node = r.insertTag("Status") status_node = repo_node.createElement("Status")
status_node.insertData(status) status_node.appendChild(repo_doc.createTextNode("active"))
r.appendChild(status_node)
self._update(repo_doc) self._update(repo_doc)
def get_status(self, repo_name): def get_status(self, repo_name):
repo_doc = self._get_doc() repo_doc = self._get_doc()
for r in repo_doc.getElementsByTagName("Repo"): for r in repo_doc.childNodes:
if r.nodeType == r.ELEMENT_NODE and r.tagName == "Repo":
if r.getElementsByTagName("Name")[0].firstChild.data == repo_name: if r.getElementsByTagName("Name")[0].firstChild.data == repo_name:
status_node = r.getElementsByTagName("Status") status_node = r.getElementsByTagName("Status")
if status_node: if status_node:
...@@ -130,11 +126,11 @@ class RepoOrder: ...@@ -130,11 +126,11 @@ class RepoOrder:
if self._doc is None: if self._doc is None:
repos_file = os.path.join(ctx.config.info_dir(), ctx.const.repos) repos_file = os.path.join(ctx.config.info_dir(), ctx.const.repos)
if os.path.exists(repos_file): if os.path.exists(repos_file):
self._doc = minidom.parse(repos_file).documentElement self._doc = minidom.parse(repos_file)
else: else:
impl = minidom.getDOMImplementation() impl = minidom.getDOMImplementation()
dom = impl.createDocument(None, "REPOS", None) dom = impl.createDocument(None, "REPOS", None)
self._doc = dom.documentElement self._doc = dom
return self._doc return self._doc
...@@ -142,7 +138,8 @@ class RepoOrder: ...@@ -142,7 +138,8 @@ class RepoOrder:
repo_doc = self._get_doc() repo_doc = self._get_doc()
order = {} order = {}
for r in repo_doc.getElementsByTagName("Repo"): for r in repo_doc.childNodes:
if r.nodeType == r.ELEMENT_NODE and r.tagName == "Repo":
media = r.getElementsByTagName("Media")[0].firstChild.data media = r.getElementsByTagName("Media")[0].firstChild.data
name = r.getElementsByTagName("Name")[0].firstChild.data name = r.getElementsByTagName("Name")[0].firstChild.data
status = r.getElementsByTagName("Status")[0].firstChild.data status = r.getElementsByTagName("Status")[0].firstChild.data
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment