UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Run python script within confined app

    Scheduled Pinned Locked Moved Unsolved App Development
    apparmorpythonnetworkhtml5
    4 Posts 2 Posters 395 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
      Reply
      • Reply as topic
      Log in to reply
      This topic has been deleted. Only users with topic management privileges can see it.
      • J Offline
        Jerzecokno
        last edited by

        I currently have an HTML5 app which needs to store large amounts of data, and which can't afford to risk eviction.

        Since I couldn't get the HTML5 API working, I worked around this issue by hosting a basic HTTP server on the user's phone, which the app could exchange data through XHR, and the server takes care of managing the data (saving data into files and exposing that same data to the app for later use). Currently, I use a simple python invocation with CGI scripts.

        My problem is the following: I cannot call the python executable from within a script while my app is confined. I can work around this by creating a python script and setting it as executable, but then it can't access the HTTP modules required for my case.

        My current (bad) solution: Putting my app in unconfined mode and giving it full system access seems to resolve the problem. However, it also allows the app to access parts of the system it needs not access, and I feel that giving my app full system access only to be able to run a simple script is overkill and a (very, very) bad practice.

        Is there any way I could make my app cleaner? Can I (and should I) bundle a custom python with modules with my app? Can I use something else to host an HTTP server with CGI support?

        arubislanderA 1 Reply Last reply Reply Quote 0
        • arubislanderA Offline
          arubislander @Jerzecokno
          last edited by

          @jerzecokno Seeing you originally started with an HTML5 app, I am assuming you don't really need a server. You only went that route to be able to write data to disk.
          So I am guessing that if you would use a WebView or WebEngineView you could use a WebChannel and a QtObject to communicate with the HTML. You can then call the necessary methods in Python from QML.

          An example of the communication between QML and HTML can be found in this repository

          πŸ‡¦πŸ‡Ό πŸ‡³πŸ‡± πŸ‡ΊπŸ‡Έ πŸ‡ͺπŸ‡Έ
          Happily running Ubuntu Touch
          Google Pixel 3a (20.04 DEV)
          JingPad (24.04 preview)
          Meizu Pro 5 (16.04 DEV)

          J 1 Reply Last reply Reply Quote 0
          • J Offline
            Jerzecokno @arubislander
            last edited by

            @arubislander Unfortunately QML is not an option for me, given I don't know the first thing about it, and despite repeated attempts to learn it, I don't expect to be capable of building and maintaining a QML app in the long term within a reasonable timeframe.

            I would've hoped that, given Ubuntu Touch supports non-QML apps, I could find a non-QML way to do it, so I could provide extended support for that app. I currently need only file storage and Content Hub support (both of which would work well if I could run a basic python script - or any equivalent), but I'd like to potentially support more OS features in the future and to fix bugs that users will report, thus I would prefer to make my app in an environment I can control enough to provide serious maintenance for it.

            If QML is really the only way, is there such a thing as a "dead simple" QML WebView template which I could maintain in the long term by changing only the scripts, without needing to change the QML part? If not, is there any other way I could do it?

            arubislanderA 1 Reply Last reply Reply Quote 0
            • arubislanderA Offline
              arubislander @Jerzecokno
              last edited by

              @jerzecokno Use clickable to create an app skeleton by choosing the Python template.
              Then copy the content of the Main.qml file of the project I pointed you to. Create a public repository somewhere and then if you have any concrete questions on how to proceed, either ask them here or join our App Development Telegram channel for more interactive support.

              πŸ‡¦πŸ‡Ό πŸ‡³πŸ‡± πŸ‡ΊπŸ‡Έ πŸ‡ͺπŸ‡Έ
              Happily running Ubuntu Touch
              Google Pixel 3a (20.04 DEV)
              JingPad (24.04 preview)
              Meizu Pro 5 (16.04 DEV)

              1 Reply Last reply Reply Quote 0
              • First post
                Last post