Python Forum
run command or do it in the script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
run command or do it in the script
#1
i was considering the decision of how to copy the permissions of a file to another file, should a do the os functions or just run the "chmod" command with the --reference option. i'm thinking i should create a module of functions that do these things that various commands do, to avoid the overhead of the command or the complexity of DIY. should i make that module? "chmodref()" would be its first function.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Why wouldn't you just use the standard library functions?
Reply
#3
A friendly interface is that of module plumbum
>>> from plumbum.cmd import chmod
>>> chmod('--reference', 'cvi1.png', 'cvi2.png')
''
Reply
#4
so running a command in a process is considered better or did they make that just for the convenience of those that have decided that it is better? i went ahead and made a couple functions.

from os import chmod,stat
def chmodref(rfn,fn,filenotfound1=None,filenotfound2=None):
    try:
        rstat = stat(rfn,follow_symlinks=False)
    except FileNotFoundError:
        return filenotfound1
    try:
        return chmod(fn,rstat.st_mode&4095,follow_symlinks=False)
    except FileNotFoundError:
        return filenotfound2
from os import chown,stat
def chownref(rfn,fn,filenotfound1=None,filenotfound2=None):
    try:
        rstat = stat(rfn,follow_symlinks=False)
    except FileNotFoundError:
        return filenotfound1
    try:
        return chown(fn,rstat.st_uid,rstat.st_gid,follow_symlinks=False)
    except FileNotFoundError:
        return filenotfound2
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Run Python 3 script with the same command on Windows, Linux, and macOS? ssrobins 3 2,742 Nov-15-2020, 07:32 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020