Author: poeml Date: Fri Feb 21 00:52:41 2014 New Revision: 8483 URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8483&view=rev Log: mb timestamps: - new mb subcommand to create a timestamp same as with the script that was in /tools - read Apache DocumentRoot from mirrorbrain.conf, if set there, and prepend it automatically to the timestamp's filename Added: trunk/mb/mb/timestamps.py Modified: trunk/mb/mb.py trunk/mb/mb/conf.py Modified: trunk/mb/mb.py URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mb/mb.py?rev=8483&r1=8482&r2=8483&view=diff ============================================================================== --- trunk/mb/mb.py (original) +++ trunk/mb/mb.py Fri Feb 21 00:52:41 2014 _at_@ -1670,6 +1670,45 @@ % (opts.commit, opts.target_dir)) + + #_at_cmdln.alias('ts') + + _at_cmdln.option('-u', '--user', dest='user', metavar='USER', + help='user owning the timestamp') + _at_cmdln.option('-g', '--group', dest='group', metavar='GROUP', + help='group owning the timestamp') + _at_cmdln.option('--no-docroot', action='store_true', default=False, + help='do not prepend the Apache DocumentRoot') + def do_timestamp(self, subcmd, opts, *args): + """${cmd_name}: Securely create timestamp marker files to be synced by the mirrors + + There's something special: files ending in "invisible" will + be made mode 0640, others 0644. + + The Apache DocumentRoot is prepended, if set in mirrorbrain.conf + (apache_documentroot setting) + + Usage: + mb timestamps [OPTS] timestampfile1 [timestampfile2...] + ${cmd_option_list} + """ + + if not args: + sys.exit('At least one filename is needed.') + + import os + docroot = self.config.dbconfig.get('apache_documentroot', '') + if docroot and not opts.no_docroot: + args = [ os.path.join(docroot, i) for i in args ] + + import mb.timestamps + mb.timestamps.create(args, user=opts.user, group=opts.group) + + + + + + if __name__ == '__main__': import sys mirrordoctor = MirrorDoctor() Modified: trunk/mb/mb/conf.py URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mb/mb/conf.py?rev=8483&r1=8482&r2=8483&view=diff ============================================================================== --- trunk/mb/mb/conf.py (original) +++ trunk/mb/mb/conf.py Fri Feb 21 00:52:41 2014 _at_@ -10,7 +10,8 @@ DEFAULTS = { 'zsync_hashes': False, 'chunked_hashes': True, - 'chunk_size': 262144 } + 'chunk_size': 262144, + 'apache_documentroot': None} class Config: """this class sets up a number dictionaries that contain configuration Added: trunk/mb/mb/timestamps.py URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mb/mb/timestamps.py?rev=8483&view=auto ============================================================================== --- trunk/mb/mb/timestamps.py (added) +++ trunk/mb/mb/timestamps.py Fri Feb 21 00:52:41 2014 _at_@ -0,0 +1,71 @@ +# encoding: utf-8 + +import os +import sys +import time +import tempfile +import pwd, grp + +explanation = """ +Should you wonder about this file, it supplies timestamps that can be +used to assess possible lags in mirroring. + +These are not used by MirrorBrain for mirror checking, but can help +human beings with verifying a mirrors setup. (Maybe MirrorBrain could/should +make use of these timestamps in the future.) + +In addition, the .timestamp_invisible is supposed to be not visible +through HTTP, FTP or rsync. This serves to ensure that a mirrors's +permission setup is correct. Keeping certain files temporarily +unreadable can be an important step in the process of publishing content. + +Feel free to contact mirrorbrain at mirrorbrain org for more information; +Thanks. + +""" + +def create(tstamps, user=None, group=None): + + epoch = int(time.time()) + utc = time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime()) + + + if user: + user = pwd.getpwnam(user).pw_uid + else: + user = os.geteuid() + + if group: + group = grp.getgrnam(group).gr_gid + else: + group = os.getegid() + + for tstamp in tstamps: + try: + # we might write in a directory not owned by root + (fd, tmpfilename) = tempfile.mkstemp(prefix = os.path.basename(tstamp), + dir = os.path.dirname(tstamp)) + except OSError, e: + sys.exit(e) + + if tstamp.endswith('invisible'): + mode = 0640 + else: + mode = 0644 + + try: + os.chown(tmpfilename, + user, + group) + except OSError, e: + sys.exit(e) + + os.chmod(tmpfilename, mode) + + f = os.fdopen(fd, 'w') + f.write('%s\n%s\n\n' % (epoch, utc)) + f.write(explanation) + f.close() + + os.rename(tmpfilename, tstamp) + _______________________________________________ mirrorbrain-commits mailing list Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/ Note: To remove yourself from this list, send a mail with the content unsubscribe to the address mirrorbrain-commits-request_at_mirrorbrain.orgReceived on Thu Feb 20 2014 - 23:52:44 GMT
This archive was generated by hypermail 2.3.0 : Fri Feb 21 2014 - 00:17:05 GMT