• WTFGuy (unregistered)

    The problem in modern dev isn't that we have so many typewriters. It's that we have so many monkeys.

    I scarcely know where to begin on this ... atrocity.

  • (nodebb)

    I hope the environment is strictly controlled, because the first loop fails miserably if someone manages to create a file in the otherwise empty directory while nothing is mounted there, seeing as how the automatic mount will calmly hide those files when the drive is actually inserted, but the file will be detected and the loop will end as if there is an actual USB key mounted...

  • (nodebb)

    Detecting a new USB drive isn't all that easy, so doing the directory listing isn't a completely insane way to do it.

    The other minor WTF that isn't mentioned is that "usb drv not detected" gets sent even when the drive is detected.

  • Debra (unregistered)

    I've always preferred ture to fasle.

  • Pyth0n (unregistered)

    Well, actually the patch check is sane. In modern Linuxen the removable media mount path is like that: /media/LOGIN/MEDIA_LABEL/media_contents (sometimes /run/media/...).

    So the assumption is that user running script has its login named exactly update. Then os.listdir('/media/update') lists all mounted pendrives by their labels.

    All the other logic is botched, but this one part is OK.

  • Hanzito (unregistered)

    Hammer, meet nail. Nail, meet hammer.

  • (nodebb) in reply to Steve_The_Cynic

    "Abandon all hope, ye who enters here".

    I mean, seriously, you should stop using the phrase "environment is controlled" - if they have such a standard for their code, they wouldn't even understand the meaning of the phrase, even if you handed them the dictionary.

    Yes, speaking from experience.

  • Sauron (unregistered)

    Borrow some real-world pythons from some snake geek.

    Let them loose in the office.

  • (nodebb)

    buf10 ... stores the string "False".

    As regular TDWTF readers should know, path.exists will return the boolean value FileNotFound... probably.

  • Duke of New York (unregistered) in reply to Hanzito

    These aren't even nails. They're rocks pounded in with bigger rocks.

  • (nodebb)

    HAHAHAHA I recently worked on something very similar and was afraid for a second this was about my code, but then I read to "Python" and breathed a sigh of relief (my stuff is in C#).

    Having read the full article, it's needless to say that I would never write something as bad as this - but the first few words of the first paragraph did get me. :)

  • enkorvaks (unregistered) in reply to Pyth0n

    Not only do they need the logged-in user to be named 'update', they also need that user logged in to some sort of session which auto-mounts USB devices. Typically, even standard desktop environments just notice and allow the user to mount it manually.

    It's possible to have a USB device auto-mount, under specific circumstances, and do something afterwards, but this method is not it.

  • (nodebb)

    twitches at yet another idiot treating a simple value as a string

    C'mon. It's a boolean. There's no need to stringify a boolean. It's an ON/OFF state, the very building blocks of computers. If you haven't been taught this much on day one of your training (which was probably an online "learn to be a h4x0r in 20 minutes!!1!" course), then it was a waste.

    I think I have found the button that turns me into interesting shades of crimson.

  • improperyour (unregistered)

    How can I get a contract to be a freelancer that gets to write this code? Did this take him(her) a long time? Was this the whole contract? Can I get paid the same way?

  • improperyour (unregistered)

    How can I get a contract to be a freelancer that gets to write this code? Did this take him(her) a long time? Was this the whole contract? Can I get paid the same way?

  • Your Name (unregistered)

    There's no event from the OS whether a new drive has been mounted/unmounted, that you could subscribe to?

  • (nodebb)

    I really love the inconsistency in the Python string syntax. Oh come on, we can debate all day on the merits of double quotes over single quotes, but is it so hard to choose one and just stick to it?

    That's one of the red flags that makes me want to throw that piece of garbage in /dev/null.

  • (nodebb) in reply to Your Name

    There's likely multiple better ways to do this, but that might imply reading some documentation when it's so much easier to reinvent (poorly) the wheel.

  • WTFGuy (unregistered)

    Ref You Name's very sensible point ...

    A legit problem with so much code being written in various scripting languages is that a) there often really are OS events published by an OS API that user code written in real full-featured languages can subscribe too. But b) that API is not surfaced in the training wheel / OS-agnostic world of python, javascript, etc.

    A secondary problem is one of training. Script jockeys are generally going to struggle with the arcana of interfacing to Windows or iOS or Linux's APIs. Many of which were designed in an era of assembler as the primary user-mode code language. Not so hard to interface with using C or equivelent. Much more challenging for newer / higher langs.

    A script language with fully debugged reliable OS abstraction layers available as built-in libraries would bridge a lot of this gap. Would.

  • (nodebb)

    Possibly buf10 is simply preceded by buf1, and followed by buf11, buf100, buf101 …

Leave a comment on “All Thumbs”

Log In or post as a guest

Replying to comment #:

« Return to Article