def run(self): if not self.options.newid: raise ZenPackException('You must specify a new id with the' ' --newid option.') zpName = self.args[0] if not os.path.isdir(zenPath('Products', zpName)): raise ZenPackException( 'Can not locate %s.' % zpName + ' This command only operates on installed ZenPacks.') (possible, msgOrId) = ZenPackCmd.CanCreateZenPack(None, self.options.newid) if possible: newId = msgOrId else: raise ZenPackException('Unable to eggify %s: %s' % (zpName, msgOrId)) self.connect() # Create new zenpack eggDir = ZenPackCmd.CreateZenPack(newId, prevZenPackName=zpName) # Copy old one into new one parts = newId.split('.') zpDir = os.path.join(eggDir, *parts) os.system('rm -rf %s' % zpDir) shutil.copytree(zenPath('Products', zpName), zpDir, symlinks=False) # Create a skins directory if there isn't one skinsDir = os.path.join(zpDir, 'skins', zpName) if not os.path.isdir(skinsDir): os.makedirs(skinsDir) # Install it ZenPackCmd.InstallEggAndZenPack(self.dmd, eggDir, link=True) # Confirm pack is eggified pack = self.dmd.ZenPackManager.packs._getOb(zpName, None) success = pack and pack.isEggPack() if success: print('%s successfully converted to %s.' % (zpName, newId)) print('The code for %s is located at $ZENHOME/ZenPacks/%s' % (newId, newId)) print('NOTE: If your ZenPack provides DataSource classes ' 'or any other python class for objects that are stored ' 'in the object database then further steps are ' 'required. Please see the Zenoss Developer Guide for ' 'more instructions.')
def run(self): if not self.options.newid: raise ZenPackException('You must specify a new id with the' ' --newid option.') zpName = self.args[0] if not os.path.isdir(zenPath('Products', zpName)): raise ZenPackException('Can not locate %s.' % zpName + ' This command only operates on installed ZenPacks.') (possible, msgOrId) = ZenPackCmd.CanCreateZenPack( None, self.options.newid) if possible: newId = msgOrId else: raise ZenPackException('Unable to eggify %s: %s' % ( zpName, msgOrId)) self.connect() # Create new zenpack eggDir = ZenPackCmd.CreateZenPack(newId, prevZenPackName=zpName) # Copy old one into new one parts = newId.split('.') zpDir = os.path.join(eggDir, *parts) os.system('rm -rf %s' % zpDir) shutil.copytree(zenPath('Products', zpName), zpDir, symlinks=False) # Create a skins directory if there isn't one skinsDir = os.path.join(zpDir, 'skins', zpName) if not os.path.isdir(skinsDir): os.makedirs(skinsDir) # Install it ZenPackCmd.InstallEggAndZenPack(self.dmd, eggDir, link=True) # Confirm pack is eggified pack = self.dmd.ZenPackManager.packs._getOb(zpName, None) success = pack and pack.isEggPack() if success: print('%s successfully converted to %s.' % (zpName, newId)) print('The code for %s is located at $ZENHOME/ZenPacks/%s' % (newId, newId)) print('NOTE: If your ZenPack provides DataSource classes ' 'or any other python class for objects that are stored ' 'in the object database then further steps are ' 'required. Please see the Zenoss Developer Guide for ' 'more instructions.')
def becomeDaemon(self): """fork twice to become a daemon""" pid = 0 try: pid = os.fork() if pid > 0: sys.exit(0) except OSError as e: print >> sys.stderr, ("fork #1 failed: %d (%s)" % (e.errno, e.strerror)) os.chdir("/") os.setsid() os.umask(0) try: pid = os.fork() if pid > 0: sys.exit(0) except OSError as e: print >> sys.stderr, ("fork #2 failed: %d (%s)" % (e.errno, e.strerror)) myname = sys.argv[0].split(os.sep)[-1] + ".pid" varhome = zenPath('var') pidfile = os.path.join(varhome, myname) if os.path.exists(varhome): file = open(pidfile, 'w') file.write(str(os.getpid())) file.close() else: print "ERROR: unable to open pid file %s" % pidfile sys.exit(1)
sys.exit(0) except OSError, e: print >>sys.stderr, ("fork #1 failed: %d (%s)" % (e.errno, e.strerror)) os.chdir("/") os.setsid() os.umask(0) try: pid = os.fork() if pid > 0: sys.exit(0) except OSError, e: print >>sys.stderr, ("fork #2 failed: %d (%s)" % (e.errno, e.strerror)) myname = sys.argv[0].split(os.sep)[-1] + ".pid" varhome = zenPath('var') pidfile = os.path.join(varhome, myname) if os.path.exists(varhome): file = open(pidfile, 'w') file.write(str(os.getpid())) file.close() else: print "ERROR: unable to open pid file %s" % pidfile sys.exit(1) def forwardDnsLookup(self, hostname): """try the forward lookup dnstries times if it fails look in cache""" try: ip = self._dnsLookup(socket.gethostbyname, hostname) self.forwarddnscache[hostname] = ip