Python program to lock and unlock files
I have absolutely no idea what the purpose of this code is. Something to do with locking and unlocking files, but why? Your code doesn't say, and neither does your post. It's hard to review code when I have no idea what it is supposed to do.
There are no docstrings. What do these functions do? What arguments should I pass?
Running shell commands and parsing their output is complex and slow. Instead, get the flags for a file by calling os.stat and set the flags for a file by calling os.chflags. Use the constants in the stat module, for example stat.UF_IMMUTABLE for the uchg flag.

To read the flags for a file:

import os, stat
flags = os.stat(filename).st_flags


To determine if a file is immutable, evaluate:

bool(flags &amp; stat.UF_IMMUTABLE)


To set the immutable flag, call:

os.chflags(filename, flags | stat.UF_IMMUTABLE)


To clear the immutable flag, call:

os.chflags(filename, flags &amp; ~stat.UF_IMMUTABLE)

Since you don't say what the purpose of this code is, I can't tell if it is a good implementation or not. If you are planning to use this mechanism for mutual exclusion (e.g. to prevent two instances of a program running at the same time) then it won't work, because it has race conditions (the flags might change between getting them and setting them).