Off-Topic > Off-Topic - Tiny Tux's Corner

[Solved] Asking for recomendations on the shell script formatting.

<< < (9/10) > >>

Paul_123:
Yes, os is an external library from here https://github.com/micropython/micropython-lib  We only include a few of the micropython libs. It’s enough for basic scripting.

Mounting extensions is a heavy IO process, but it does significantly improve the time loading extensions during boot by forking up to the number of cpu cores.   Micropython support for python’s threading module is still fairly new and limited.

CardealRusso:

--- Quote from: Paul_123 on July 20, 2023, 10:30:45 AM ---The adaptation of "indentation languages"

--- End quote ---

--- Quote from: Rich on July 20, 2023, 11:31:07 AM ---Same here.

--- End quote ---
Hi. I will not insist on such changes anymore as it is clear that the disapproval is due to the learning curve and middle age effects; Regardless of Lua or Python (and I would not like to take that responsibility if it was assigned to me). I would just really like to know why not integrate micropython with the other ports for symmetry purposes?

Although not insisting, I would like to leave some comparisons I made before giving up that may be interesting; First, Lua is extremely fast.
I honestly don't know if this speed would benefit TinyCore in any way, but in basic synthetic tests, lua managed, again, to surprise me.
One such test I did was a counter up to 1 billion; C finished in 2 seconds, Lua in 9, Micropython (custom) 47 seconds, Micropython (standard) 1:24, Python took about 3 minutes and bash never finished (I canceled about 5 minutes in because I thought it would never finish). https://pastebin.com/raw/DmEQB95d

About MicroPython, I started doing, again, what supposedly could be something like tce-size. I had a little knowledge about python,  and in these last hours I learned a lot. Here is an (incomplete) example of tce-size for python:  https://pastebin.com/7wLZDmVa
As I mentioned before, the idea is to use a programming language that can be more easily "mastered" by newbies, so that way, community development can maybe move along a bit more. And with that I allow myself to analyze small portions of the three codes (fragmented and unordered, which might look a little messy)

Getting the list and the tree.
SH:

--- Code: ---tce-size:
tce-fetch.sh sizelist.gz || exit 1
touch sizelist
tce-fetch.sh "$app".tree >/dev/null 2>&1 || echo "$app" > "$app".tree
tce-fetch.sh:
if [ "$1" == "-O" ]; then
shift
wget -cq -O- "$MIRROR"/"${1//-KERNEL.tcz/-${KERNELVER}.tcz}" <-- (I confess that I still don't understand how this works)
else
F="${1//-KERNEL.tcz/-${KERNELVER}.tcz}"
[ -f "$F" ] && rm -f "$F"
wget -cq "$MIRROR"/"$F"
fi
--- End code ---
MPY:

--- Code: ---def GetRemoteTextFile(filename):
    response = urequests.get(f"{BuildMirror()}/tcz/{filename}")
    if response.status_code == 200:
        return response.text
    else:
        print(f"Error downloading file {filename}. Status code: {response.status_code}")
        sys.exit(1)
...
sizelist = GetRemoteTextFile("sizelist")
packageTree = GetRemoteTextFile(f"{package}.tree")

--- End code ---
Dealing with the .tcz or lack thereof in the package name:
sh:

--- Code: ---   app=${app%.tcz}
   app="$app.tcz"

--- End code ---
MPY:

--- Code: ---if not package.endswith(".tcz"):
    package += ".tcz"

--- End code ---

Handling dependencies:
SH:

--- Code: ---for F in `sed 's/ //g' "$app".tree | sort -f | uniq`; do
      size=`grep -w "^$F" sizelist  | awk '{print $2}'`
      case $size in
      [0-9]*)
sizemb=`Fixed3Div $size $M`
if [ -f "$localtce"/optional/"$F" ]; then
totalsize_installed=$(($totalsize_installed + $size))
echo -n "  "
printf "%-40s" $F
printf " %10d, %6.2f MB\n" $size $sizemb
else
echo -n "+ "
totalsize_needed=$(($totalsize_needed + $size))
printf "%-40s %10d, %6.2f MB\n" $F $size $sizemb
fi
      ;;
      *)
printf "%-40s Error, not found \n" $F
      ;;
      esac
done
}

--- End code ---

MPY (incomplete):

--- Code: ---# Create a dictionary mapping the file name to its size in bytes
size_dict = {line.split()[0]: int(line.split()[1]) for line in sizelist.splitlines()}
 
# Print the results directly from the list comprehension
print("\n".join(f"{filename:<40} {size_in_bytes:<13} {bytes_to_mb(size_in_bytes):<8.2f}" for filename, size_in_bytes in size_dict.items() if filename in packageTree))

--- End code ---
It could be simpler, remembering the lua:

--- Code: ---for treeline in packageTree.splitlines():
    for sizeline in sizelist.splitlines():
        currentSizeLine = sizeline.split(" ")
        if treeline.strip() == currentSizeLine[0]:
            filename = currentSizeLine[0]
            size_in_bytes = int(currentSizeLine[1])
            size_in_mb = convert_bytes_to_mb(size_in_bytes)
            print(f"{filename:<40} {size_in_bytes:<13} {size_in_mb:<8}")

--- End code ---

Just replacing shelling outs with built-in functions, as well as not using regex (or something similar to regex) makes the code easier to understand. This way, half of the code is understandable just by reading it, eliminating (not much) the need to understand things like "\" or "\\" or "\\\" or "\\\\/////" or maybe "||||||||" or rather, why not "\o/\o/\o/\o/\o/"

GNUser:

--- Quote from: CardealRusso on July 21, 2023, 05:25:14 PM ---I will not insist on such changes anymore...I would just really like to know why not integrate micropython with the other ports for symmetry purposes?

--- End quote ---
Hi CardealRusso. This is easy to answer. It's because no user has stepped up to submit a micropython extension for the other ports. Many users insist on changes and ask for explanations, but few submit extensions and create pull requests.


--- Quote from: CardealRusso on July 21, 2023, 05:25:14 PM ---it is clear that the disapproval is due ... middle age effects

--- End quote ---
Hi Rich. Do the forum rules allow this?

CardealRusso:

--- Quote from: GNUser on July 21, 2023, 07:10:34 PM ---submit a micropython extension for the other ports.

--- End quote ---
HI. Apparently there is no micropython extension in any version of tinycore, it's included directly in rootfs. as mentioned in

--- Quote from: Rich on July 20, 2023, 11:28:02 AM ---It is included in the rootfs as  /usr/bin/micropython.

--- End quote ---


--- Quote from: GNUser on July 21, 2023, 07:10:34 PM ---Hi Rich. Do the forum rules allow this?

--- End quote ---
Sorry if I sounded rude. In my culture, old age is impossible to be used as any form of offense, it's a blessing to reach such an age and be healthy.

We believe, however, that there is a way of acting that is inherited long before we became homosapiens; Old people don't learn, they teach.

It does not mean that old people are incapable of learning, but that they are simply less likely to learn because they feel they are in the position of life teachers.

Rich:
Hi GNUser

--- Quote from: GNUser on July 21, 2023, 07:10:34 PM --- ...
--- Quote from: CardealRusso on July 21, 2023, 05:25:14 PM ---it is clear that the disapproval is due ... middle age effects
--- End quote ---
Hi Rich. Do the forum rules allow this?
--- End quote ---
This was obviously not directed at me since at 64 I'm well
past middle aged, so I'll allow it.  ;D

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version