Login to the input system

Suppose My login ID is tom2deu. I have one Python program. Now I'm going to change this program to Python.

My question

Can we print my notepad login ID or any other file?

means that we can print out any detail of the person (login ID) who registered the system and changed the program.

0
python
source share
4 answers

I'm not sure what problem you are trying to solve, but if you want to track changes to the source files, you probably should use a version control system such as Subversion . In a nutshell, he will track all changes to the source files and manage conflicts (when two people try to change the file at the same time).

+2
source share

If you need a general solution, you should adopt pyinotify , which is the shell for the Linux inotify kernel (kernel version> = 2.6.13). With it, you can register for certain events in the file system, for example, for example. in the following code:

 from pyinotify import WatchManager, ThreadedNotifier, ProcessEvent, EventsCodes file_to_monitor = "/tmp/test.py" class FSEventHook(ProcessEvent): def __init__(self, watch_path): ProcessEvent.__init__(self) wm = WatchManager() wm.add_watch(watch_path, EventsCodes.ALL_FLAGS['IN_CLOSE_WRITE'], rec=False) self.notifier = ThreadedNotifier(wm, self) def start(self): self.notifier.start() def process_IN_CLOSE_WRITE(self, event): if os.path.isfile(event.pathname): print "%s changed"%pathname fshook = FSEventHook(file_to_monitor) fshook.start() 

The following events: IN_MOVED_FROM, IN_CREATE, IN_ONESHOT, IN_IGNORED, IN_ONLYDIR, IN_Q_OVERFLOW, IN_MOVED_TO, IN_DELETE, IN_DONT_FOLLOW, IN_CLOSE_WRITE, IN_MOVE_SELF, IN_ACCESS, IN_MODIFY, IN_MASK_ADD, IN_CLOSE_NOWRITE, IN_ISDIR, IN_UNMOUNT, IN_DELETE_SELF, ALL_EVENTS, IN_OPEN, IN_ATTRIB . For each of them, you must implement your own method process_XXX() , which will be called back if the event is triggered.

+2
source share

try these.

import os
print os.environ ['USERNAME']

or

os.getlogin ()

then save the variable and use file processing to save it as a text file.

+1
source share

What are you asking if you can track who made changes to the file. And this is not a Python issue, but an operating system issue. To be able to track who changed the file, you need to install an audit system. If you use Linux, it has an audit subsystem that you can configure to track this information, I think.

0
source share

All Articles