l.s.s.b.LaunchpadScript : class documentation

Part of lp.services.scripts.base View In Hierarchy

Known subclasses: lp.codehosting.scripts.modifiedbranches.ModifiedBranchesScript, lp.registry.scripts.closeaccount.CloseAccountScript, lp.registry.scripts.createbotaccount.CreateBotAccountScript, lp.registry.scripts.populate_distroseriesdiff.PopulateDistroSeriesDiff, lp.registry.scripts.suspendbotaccount.SuspendBotAccountScript, lp.services.scripts.base.LaunchpadCronScript, lp.services.scripts.tests.test_feature_controller.FakeScript, lp.soyuz.scripts.ftpmasterbase.SoyuzScript, lp.soyuz.scripts.ppareport.PPAReportScript, lp.translations.scripts.gettext_check_messages.GettextCheckMessages, lp.translations.scripts.remove_translations.RemoveTranslations, lp.translations.scripts.reupload_translations.ReuploadPackageTranslations, lp.translations.scripts.upload_translations.UploadPackageTranslations, lp.translations.utilities.translationmerger.MergeExistingPackagings, lp.translations.utilities.translationmerger.MessageSharingMerge

A base class for runnable scripts and cronscripts.

Inherit from this base class to simplify the setup work that your script needs to do.

What you define:
  • main()
  • add_my_options(), if you have any
  • usage and description, if you want output for --help
What you call:
  • lock_and_run()
If you are picky:
  • lock_or_die()
  • run()
  • unlock()
  • build_options()
What you get:
  • self.logger
  • self.txn
  • self.parser (the OptionParser)
  • self.options (the parsed options)

"Give me convenience or give me death."

Method __init__ Construct new LaunchpadScript.
Method handle_options Undocumented
Method name Enable subclasses to override with command-line arguments.
Method dbuser Enable subclasses to override with command-line arguments.
Method main Define the meat of your script here. Must be defined.
Method add_my_options Optionally customize this hook to define your own options.
Method login Super-convenience method that avoids the import.
Method lockfilename Return lockfilename.
Method lockfilepath Undocumented
Method setup_lock Create lockfile.
Method lock_or_die Attempt to lock, and sys.exit(1) if the lock's already taken.
Method unlock Release the lock. Do this before going home.
Method run Actually run the script, executing zcml and initZopeless.
Method record_activity Hook to record script activity.
Method lock_and_run Call lock_or_die(), and then run() the script.
Method _init_zca Initialize the ZCA, this can be overridden for testing purposes.
Method _init_db Initialize the database transaction.
def __init__(self, name=None, dbuser=None, test_args=None, logger=None):
Construct new LaunchpadScript.

Name is a short name for this script; it will be used to assemble a lock filename and to identify the logger object.

Use dbuser to specify the user to connect to the database; if not supplied a default will be used.

Specify test_args when you want to override sys.argv. This is useful in test scripts.

ParametersloggerUse this logger, instead of initializing global logging.
def handle_options(self):
Undocumented
@property
def name(self):
Enable subclasses to override with command-line arguments.
@property
def dbuser(self):
Enable subclasses to override with command-line arguments.
def main(self):
overridden in lp.archivepublisher.scripts.generate_contents_files.GenerateContentsFiles, lp.archivepublisher.scripts.generate_ppa_htaccess.HtaccessTokenGenerator, lp.archivepublisher.scripts.processaccepted.ProcessAccepted, lp.archivepublisher.scripts.processdeathrow.DeathRowProcessor, lp.archivepublisher.scripts.publish_ftpmaster.PublishFTPMaster, lp.archivepublisher.scripts.publishdistro.PublishDistro, lp.archiveuploader.scripts.processupload.ProcessUpload, lp.bugs.scripts.bugnotification.SendBugNotifications, lp.bugs.scripts.checkwatches.__init__.CheckWatchesCronScript, lp.bugs.scripts.cveimport.CVEUpdater, lp.code.scripts.revisionkarma.RevisionKarmaAllocator, lp.codehosting.scripts.modifiedbranches.ModifiedBranchesScript, lp.registry.scripts.closeaccount.CloseAccountScript, lp.registry.scripts.createbotaccount.CreateBotAccountScript, lp.registry.scripts.populate_distroseriesdiff.PopulateDistroSeriesDiff, lp.registry.scripts.standing.UpdatePersonalStanding, lp.registry.scripts.suspendbotaccount.SuspendBotAccountScript, lp.scripts.garbo.BaseDatabaseGarbageCollector, lp.services.apachelogparser.script.ParseApacheLogs, lp.services.scripts.tests.cronscript-crash.CrashScript, lp.services.scripts.tests.example-cronscript.Script, lp.services.scripts.tests.test_feature_controller.FakeScript, lp.soyuz.scripts.expire_archive_files.ArchiveExpirer, lp.soyuz.scripts.ftpmasterbase.SoyuzScript, lp.soyuz.scripts.ppakeygenerator.PPAKeyGenerator, lp.soyuz.scripts.ppareport.PPAReportScript, lp.translations.scripts.gettext_check_messages.GettextCheckMessages, lp.translations.scripts.import_queue_gardener.ImportQueueGardener, lp.translations.scripts.po_import.TranslationsImport, lp.translations.scripts.remove_translations.RemoveTranslations, lp.translations.scripts.reupload_translations.ReuploadPackageTranslations, lp.translations.scripts.translations_to_branch.ExportTranslationsToBranch, lp.translations.scripts.upload_translations.UploadPackageTranslations, lp.translations.utilities.translationmerger.MergeExistingPackagings, lp.translations.utilities.translationmerger.MessageSharingMerge
Define the meat of your script here. Must be defined.

Raise LaunchpadScriptFailure if you encounter an error condition that makes it impossible for you to proceed; sys.exit(1) will be invoked in that situation.

def add_my_options(self):
overridden in lp.archivepublisher.scripts.generate_contents_files.GenerateContentsFiles, lp.archivepublisher.scripts.generate_ppa_htaccess.HtaccessTokenGenerator, lp.archivepublisher.scripts.processaccepted.ProcessAccepted, lp.archivepublisher.scripts.processdeathrow.DeathRowProcessor, lp.archivepublisher.scripts.publish_ftpmaster.PublishFTPMaster, lp.archivepublisher.scripts.publishdistro.PublishDistro, lp.archiveuploader.scripts.processupload.ProcessUpload, lp.bugs.scripts.checkwatches.__init__.CheckWatchesCronScript, lp.bugs.scripts.cveimport.CVEUpdater, lp.codehosting.scripts.modifiedbranches.ModifiedBranchesScript, lp.registry.scripts.closeaccount.CloseAccountScript, lp.registry.scripts.createbotaccount.CreateBotAccountScript, lp.registry.scripts.populate_distroseriesdiff.PopulateDistroSeriesDiff, lp.registry.scripts.suspendbotaccount.SuspendBotAccountScript, lp.scripts.garbo.BaseDatabaseGarbageCollector, lp.soyuz.scripts.expire_archive_files.ArchiveExpirer, lp.soyuz.scripts.ftpmasterbase.SoyuzScript, lp.soyuz.scripts.ppakeygenerator.PPAKeyGenerator, lp.soyuz.scripts.ppareport.PPAReportScript, lp.translations.scripts.gettext_check_messages.GettextCheckMessages, lp.translations.scripts.remove_translations.RemoveTranslations, lp.translations.scripts.reupload_translations.ReuploadPackageTranslations, lp.translations.scripts.translations_to_branch.ExportTranslationsToBranch, lp.translations.scripts.upload_translations.UploadPackageTranslations, lp.translations.utilities.translationmerger.MessageSharingMerge

Optionally customize this hook to define your own options.

This method should contain only a set of lines that follow the template:

self.parser.add_option("-f", "--foo", dest="foo",
default="foobar-makes-the-world-go-round", help="You are joking, right?")
@log_unhandled_exception_and_exit
def login(self, user=ANONYMOUS):
Super-convenience method that avoids the import.
@property
def lockfilename(self):
Return lockfilename.

May be overridden in targeted scripts in order to have more specific lockfilename.

@property
def lockfilepath(self):
Undocumented
def setup_lock(self):
Create lockfile.

Note that this will create a lockfile even if you don't actually use it. GlobalLock.__del__ is meant to clean it up though.

@log_unhandled_exception_and_exit
def lock_or_die(self, blocking=False):
Attempt to lock, and sys.exit(1) if the lock's already taken.

Say blocking=True if you want to block on the lock being available.

@log_unhandled_exception_and_exit
def unlock(self, skip_delete=False):
Release the lock. Do this before going home.

If you skip_delete, we won't try to delete the lock when it's freed. This is useful if you have moved the directory in which the lockfile resides.

@log_unhandled_exception_and_exit
def run(self, use_web_security=False, isolation=None):
Actually run the script, executing zcml and initZopeless.
def _init_zca(self, use_web_security):
Initialize the ZCA, this can be overridden for testing purposes.
def _init_db(self, isolation):
Initialize the database transaction.

Can be overridden for testing purposes.

def record_activity(self, date_started, date_completed):
Hook to record script activity.
@log_unhandled_exception_and_exit
def lock_and_run(self, blocking=False, skip_delete=False, use_web_security=False, isolation='read_committed'):
Call lock_or_die(), and then run() the script.

Will die with sys.exit(1) if the locking call fails.

API Documentation for Launchpad, generated by pydoctor at 2022-06-16 00:00:12.