Package: oschmod
oschmodoschmodsets consistent file permissions across Windows, Linux and macOS.oschmod TL;DRoschmodbringschmodfunctionality toWindows, macOS, and Linux! If you're not familiar,chmodis a handy macOS and Linux-only tool for setting file permissions.Prior tooschmod, Windows file permissions couldn't be set in the familiarchmodway. Tools did not translatechmod-style permissions into Windows-style file permissions. Even though Python'sos.chmod()sets read, write, and execute file permissions, on Windows,os.chmod()basically has no effect. Even worse, Python on Windows gives no warnings or errors. If you think you set file permissions on Windows withos.chmod(), you're wrong!oschmodallows you to set consistent file permissions in a consistent way across platforms.Read more aboutoschmodon MediumFor more background, have a look at theoschmod Wiki.Installation$pipinstalloschmodGNU Documentationoschmodchanges the file mode bits of each given file according to mode, which can be either a symbolic representation of changes to make, or an octal number representing the bit pattern for the new mode bits.The format of a symbolic mode is[ugoa...][+-=][perms...]where perms is zero or more letters from the setrwx. Multiple symbolic modes can be given, separated by commas.A combination of the lettersugoacontrols which users' access to the file will be changed: the user who owns it (u), other users in the file's group (g), other users not in the file's group (o), or all users (a). If none of these are given, the effect is as ifawere given.(Modified from the GNU manpage for chmod.)Command line interfaceoschmodbrings the ability to set consistent file permissions using the command line to Windows, macOS, and Linux platforms. If you are familiar withchmod,oschmodworks similarly, albeit with fewer options.$oschmod-husage: oschmod [-h] [-R] mode objectChange the mode (permissions) of a file or directorypositional arguments:mode        octal or symbolic mode of the objectobject      file or directoryoptional arguments:-h, --help  show this help message and exit-R          apply mode recursivelyCommand line examplesYou can use symbolic (e.g., "u+rw") or octal (e.g., "600) representations of modes. Multiple mode modifications can be made in a single call by separating modifiers with commas.Symbolic representation examplesSymbolic representation mode modifiers have three parts:whom:To whom does the modification apply? You can include zero or more of[ugoa]*whereais for all,uis for the file owner (i.e., "user"),gis for the file group, andois for others. In other words,ugois equivalent toa. Also, if you do not provide a "whom,"oschmodassumes you meana(everyone).operation:Which operation should be applied? You must include one and only one operation,[+-=]{1}, per modifier (although you can have multiple modifiers).+adds permissions,-removes permissions, and=sets permissions regardless of previous permissions.+and-modifications often depend on the current permissions.permission:Which permission or permissions will be affected? You can include zero or more of[rwx]*whereris for read,wis for write, andxis for execute. If you do not include a permission with+or-(e.g.,u-), the modifier has no effect. However, if you use no permissions with=(e.g.,o=), all permissions are removed.Example 1:To give everyone execute permissions on a file (all of these are equivalent):$oschmod+x<filename>$oschmoda+x<filename>$oschmodugo+x<filename>Example 2:To remove read, write, and execute permissions from the file group and all others (these are equivalent):$oschmodgo-rwx<filename>$oschmodgo=<filename>Example 3:To give the file owner read and execute permissions, and remove execute permissions from the group and all others:$oschmodu+rx,go-x<filename>Example 4:To give everyone all permissions, and then remove execute write from the group, and execute from all others:$oschmoda+rwx,g-w,o-x<filename>Octal representation examplesFor more about what octal representations mean, seethis articleon Medium.Example 5:To give everyone read, write, and execute permissions on a file:$oschmod777<filename>Example 6:To lock down a file to just give the file owner read, write, and execute permissions and deny all permissions to everyone else:$oschmod700<filename>Python usageYou can useoschmodfrom Python code. Any of the command line examples above will work very similarly. For example,Example 4above, in Python code, would look like this:importoschmodoschmod.set_mode("myfile","a+rwx,g-w,o-x")Example 5above, in Python code, could be done in two ways:importoschmodoschmod.set_mode("myfile","777")oschmod.set_mode("myfile",0o777)oschmodis compatible with bitwise permissions as defined in thestatmodule. To give a file's owner read, write, and execute permissions and deny the group and others any permissions (i.e., equivalent of700):importoschmodimportstatoschmod.set_mode('myfile',stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR)Replacingos.chmod()withoschmodshould usually be an easy drop-in replacement. Replacement will allow you to get consistent file permission settings on Windows, macOS, and Linux:If this is your Python code usingos.chmod():importosos.chmod('myfile1','u+x')os.chmod('myfile2',0o777)The replacement usingoschmodis very similar:importoschmodoschmod.set_mode('myfile1','u+x')oschmod.set_mode('myfile2',0o777)Changelog0.3.0Commit Delta:Change from 0.2.4 releaseReleased: 2020.05.27Summary:Adds symbolic representation for mode changes (e.g.,+x,u+rwx,ugo-x).0.2.4Commit Delta:Change from 0.2.2 releaseReleased: 2020.04.21Summary:Add command line interface (CLI).0.2.2Commit Delta:Change from 0.2.0 releaseReleased: 2020.04.21Summary:Fix issue with account lookup failing with error (No mapping between account names and security IDs was done.).0.2.0Commit Delta:Change from 0.1.5 releaseReleased: 2020.04.20Summary:Add recursive version ofoschmod.set_mode():oschmod.set_mode_recursive()0.1.5Commit Delta:Change from 0.1.4 releaseReleased: 2020.04.17Summary:Create Linux version of permissions test (oschmod.perm_test())0.1.4Commit Delta:Change from 0.1.0 releaseReleased: 2020.04.17Summary:Revise Windows to keep permissions an object already has for SYSTEM/NT AUTHORITY and don't include those permissions in mode calculation.Fix various minor cosmetic issues.0.1.0Commit Delta:Change from 0.0.0 releaseReleased: 2020.04.15Summary:Initial release