Beiträge von wooshman

    "I would assume, that something like the creation of the variable name and the usage of "exec" is needed."

    kenatonline was spot on. With this I looked into what you meant and found a plugin as an example which indeed does exactly what you thought.


    exec('config.plugins.test.' + lines[a] + ' = ConfigText(default = "")')
    exec('config.plugins.test.' + lines[a] + '.value = myval')
    exec('config.plugins.test.' + lines[a] + '.save()')


    So now on the face of it I can read and write to the settings file with just a few lines of text.

    Dre


    I am not being funny or awkward towards you but you have provided examples which are out of date compared to the new explanations and examples, this is why I am getting confused. I have already that my presvious early posts we not correct.


    create the CofigSubsection (as in the example I gave you in one of the first posts)


    Config.plugins.test.icon[n].pixel
    Config.plugins.test.icon[n].name
    Config.plugins.test.icon[n].picture

    is not relevant to where we are now at because I don't know the names


    To change your example to reflect wouldn't we have this:


    Code
    def initProfileConfig():
            s = ConfigSubsection()
            s.lines[a] =  ConfigText(default = "")
            s.lines[a] = ConfigText(default = "")
            s.lines[a]= ConfigText(default = "")
            config.plugins.test.append(s)
            return s


    Would this work though because you said lines[a] is a variable ??

    OK


    So


    Config.plugins.test.icon[n].pixel
    Config.plugins.test.icon[n].name
    Config.plugins.test.icon[n].picture




    are "pixel", "name" and "picture" predefined things within Engima 2? Please can you confirm this for me?



    If so it was pure coincidence that I chose "pixel", "myicon" and "picture" in my example and this has confused me so much. I will also then start from the beginning asking questions. I know you are trying to make me work for my solution and appreciate that but when I am seeing "pixel" and "picture" in your code which I used as an example a long time ago it has confused the hell out of me.



    Your patience is appreciated

    Thanks Dre
    Because I don't fully understand what it is I am actually writing. Not knowing what I am writing means I can't fix it when I break it.


    I have no doubt that those steps above will work, but writing the code to do that without understanding makes it very difficult.


    I will look closely at he above and see what I can do, but don't hold your breath.
    ----------------------------------


    Code
    def initProfileConfig():
            s = ConfigSubsection()
            s.pixel =  ConfigText(default = "")
            s.name = ConfigText(default = "")
            s.picture = ConfigText(default = "")
            config.plugins.test.icon.append(s)
            return s


    presumes I know the names - pixel, name, picture, but I don't. At this step they will only be in a list. Again, how would I loop the list to get get the above. Nowhere in any of this will I know the names of the icons without manually opening either the downloaded txt file or open the settings file.


    I have explained the best I can and provided my current files and code.

    100% correct I would say I couldn't have written it better myself but I failed to that that.


    The only thing which is slightly wrong is the running index number. I used that just for example, the actual data is various icon names


    so the actual line will look like
    config.plugins.test.pear=false


    config.plugins.test.salad=false

    config.plugins.test.chair=false



    but because they are icons it made more sense and was clearer to use the icon1, icon2, icon3 method. There is no index number on the icon name.


    Apart from that you know exactly what I have and what I am looking to achieve.


    Again, this is nothing illegal, I am purely trying to create plugin which a user can simply run and then close which saves them needed to go and enable or disable icons which can take time and introduces the risk of error. I would rather spend my time creating something that makes a users life easier.

    At present I want to remove them all from settings by giving a value of "" to all of them. But using the lines[a] is my problem as I can't seem to do it. If you could help with using lines[a] in place of my icon name I think I will then be able to use it again for adding the icons back to the settings file before I save it.


    I don't doubt what you are saying one little bit but don't really understand what ConfigSubList really is.
    config.plugins.test = ConfigSubsection()


    config.plugins.test. ?? ConfigSubList




    On a loop I am expecting this to happen


    Code
    config.plugins.test.icon1 = ConfigText(default = "")
    	config.plugins.test.icon1.value = myval
    	config.plugins.test.icon1.save()
    	config.plugins.test.icon2 = ConfigText(default = "")
    	config.plugins.test.icon2.value = myval
    	config.plugins.test.icon2.save()
    	config.plugins.test.icon3 = ConfigText(default = "")
    	config.plugins.test.icon3.value = myval
    	config.plugins.test.icon3.save()
    	config.plugins.test.save()


    Once this has been done I am going to read a second txt file which will could contain:

    Code
    icon3
    icon5
    icon11
    icon24


    which I will then loop through and add to the settings file:

    Code
    myval = "false"
    while b < bb:
    	icon = newlines[b]
    	config.plugins.test.icon = ConfigText(default = "")
    	config.plugins.test.icon.value = myval
    	config.plugins.test.icon.save()
    	config.plugins.test.save()
    b += 1
    configfile.save()

    My very first example using icon1 as the ConfigSubList was incorrect as I had to many elements. I know you will be shaking your head at me right now but this is the first real attempt at anything decent for a plugin and was a school boy error.


    Below is exactly what I am working with and I presume it will change any exmples you have given me for which I am sorry.


    This is what I am working with in the settings file

    Code
    config.plugins.test.icon1 = false
    config.plugins.test.icon2 = false
    config.plugins.test.icon3 = false
    config.plugins.test.icon4 = false
    config.plugins.test.icon5 = false


    and the content of my list.txt is

    Code
    icon1
    icon2
    icon3
    icon4
    icon5
    icon6
    icon7


    I have re-arranged my code to make it tidier. Reading the txt file is now done before anything else which leaves me with a neat

    Thanks Dre, sorry, I forgot about using code tags. I tried setting icon = lines[a] and although never crashed it didn't do anything in the settings file either.





    I have shown a message box to check that lines[a] is the name of the icon and also aa to check the total len(lines) and they both show the expected result


    The above is all the code I have for this part of the plugin, which as I said before works if I know the name of icon and add it directly, but am failing to be able to use the name stored in lines[a].

    HI Dre


    I do not give up easily. I can write to and remove entries from the settings file providing I include the name of the entry in full using both of your replies.


    myval = "something"



    config.plugins.test.icon7 = ConfigText(default = "")
    config.plugins.test.icon7.value = myval
    config.plugins.test.icon7.save()


    configfile.save()



    Using the above I can create a new settings entry, edit a value or remove from the settings file.


    Please can you tell me (and believe me I have tried everything I can think of) do do it this way


    lines = []
    # code here to populate list with icon names



    a = 0
    aa = len(lines)
    while a < aa:


    config.plugins.iptvplayer.lines[a] = ConfigText(default = "")
    config.plugins.iptvplayer.lines[a].value = myval
    config.plugins.iptvplayer.lines[a].save()
    a += 1


    configfile.save()


    I have tried append, but I think this is screen menu related, I have tried ' + lines[a] + ' I have tried all sorts but haven't figured it out.


    Many thanks in advance.


    The problem is that I still don't have the complete picture. I understand that you want to temporaly overwrite settings written by an other plugin. But I don't know what the other plugin does. And the way you describe everything and making sure we only get a blur picture I'm pretty sure it does something illegal.

    No, it is not illegal in the least Dre, I merely want to edit the settings of a third party open source plugin (which are stored in the settings file) via a remote config file instead of the end user having to load the third party plugin and go through all the settings themselves each time it is needed. I am actually trying to make life easier for people by removing the need for them to edit anything. Currently I don't want to spell out what I am working on as it is an idea I have had for a while now which is why it is a blurred picture. Once released the code will be freely available. It is also for the same reason I asked about sending a PM so the idea doesn't get used before my own release. I didn't realise that trying to protect my idea was against board rules.


    I appreciate that all the code required is in front of me, but piecing it together is what I am struggling with. Nowhere have I insisted that I will not use it. I came and asked for help, why would I not use the information given in return.


    Sorry to have wasted your support time gutemine, asking questions as someone completely new to python, a great way to encourage people.

    Ok, that is fair comment, I didn't know it worked like that. The third party plugin instantly save to settings so I thought I needed to do the same.


    It doesn't change the fact that I still have to read existing values and compare them to new settings though weather in settings or in memory. I still have a list of icons added by a third party plugin and I need to be able to either keep/replace or append depending on what icons are in my list. I do know that the third party plugin saves to settings all the time.


    I understand what you are saying, but the end result required is still the same.


    Would you mind me sending you a PM please so I can explain better and precisely?


    Thanks
    Woosh

    The reason is because the values are already stored in settings by another plugin and I have no control over how the plugin works. Instead of using the other plugin to manually make changes, I want to be able to change the icons using a remote file. There is no way for me to physically run the original plugin on all boxes and this will make the users life easier, I can do it via a remote file, they simply open he new plugin and the work is done.


    As for twisted vs urllib, I don't know what this is as I am so new to python and learning as I go.


    I don't necessarily need to remove the setting if it already exists and will be put back there, it can just remain there, but I am using simple logic as I am unsure of what you can do with it all.

    OK so I am lost and can't get it to work for me, just a lot of crashes.


    This is what I am trying to achieve.


    My config file is on a web server and gets loaded into a list when a button is pressed. The contents of the file is names of icons:


    icon1
    icon4
    icon5
    icon7
    icon9


    The file can list up to 36 icons



    my settings file currently contains:


    config.plugins.test.icon1=false
    config.plugins.test.icon3=false
    config.plugins.test.icon5=false
    config.plugins.test.icon9=false


    I download this file and save it locally. I save it into a tmp folder so I can delete it when I am finished. This forces a new download the next time the plugin runs.


    Code
    target = 'http://www.webserver.co.uk/foldername/configfile.txt'configfile = urllib.URLopener()
    configfile.retrieve(target + target_url, "/usr/lib/enigma2/python/Plugins/Extensions/test/tmp/configfile.txt") # having a local copy here allows me to delete it aferwards forcing a new file load next time


    I now read the file into a list

    Code
    data = /usr/lib/enigma2/python/Plugins/Extensions/test/tmp/configfile.txt"list = []file = open(data, 'r') for line in file:     list.append(line)     listcount = len(list)



    now this is where I get completely stuck and don't know what I I am doing. Even trying with one value not in a list I cannot get it to work.


    Python
    from Components.config import config, ConfigSubsection, ConfigSelection, ConfigDirectory, ConfigYesNo, ConfigOnOff, Config, ConfigInteger, ConfigSubList, ConfigText, getConfigListEntry, configfile
    
    
    		config.plugins = ConfigSubsection()config.plugins.test = ConfigSubList()


    From here I get lost.


    What I need to happen is:


    Anything that is in the configfile gets added to the settings file


    config.plugins.test.icon1=false
    config.plugins.test.icon4=false
    config.plugins.test.icon5=false
    config.plugins.test.icon7=false
    config.plugins.test.icon9=false


    Anything that is no longer in the configfile gets removed from settings


    config.plugins.test.icon5=false
    config.plugins.test.icon9=false
    The settings file then gets saved

    configfile.save()




    To remove them I think I would need to loop from 1 - 36. This would be before adding the new ones.

    Code
    x = 0while x < 36:     config.plugins.test.icon[x] = false # find every entry and remove     x += 1




    I am at a loss. I am sorry if it simple for you, but this really has me beaten.


    Thanks in advance again.


    PS, the code window is joining my lines together for some reason. I have not coded it like that.

    Thank you very much indeed.


    I am now trying to digest all that and piece it together. I am not saying I will be able to make sense of it or make it work but I will try.


    So all of that is required to read those three settings? I dread to think what saving it is going to look like.



    Thanks again.

    HI dre, thanks for the reply


    Ok, so if I could re-structure my plugin process and knew the name of each entry, how would I loop to read the entires?


    list one to see if in settinga:
    icon1
    icon2
    icon3


    in settings:
    config.plugins.test.icon1 = pixel


    config.plugins.test.icon1 = myicon


    config.plugins.test.icon1 = picture






    config.plugins.test = ConfigSubsection()


    loop code?



    Also, what is the contents of config.plugins.test and is it a list?


    Thanks again.


    Please bear in mind I am a noob

    Hi, I am new to the world of Enigma2 and python but have a php background.


    I have written some basic plugins for Enigma2 which work, but now I am trying to read and write to the settings file: etc/enigma2/settings


    The problem I have is that I don't know what the exact name of the value will be so cannot address it using code from other plugins.


    I am looking for a way to remove



    config.plugins.test.random=false
    config.plugins.test.anotherrandom=false
    config.plugins.test.something=false
    config.plugins.test.different=false


    from the settings file, then save a list with similar data back to the settings file.


    I understand that I need


    config.plugins.test = ConfigSubsection()



    but without knowing the actual names of random, another random etc I am very lost of how to do what I am aiming for.


    Many thanks n advance
    Woosh