Baker 1.2

5.0/10 (3 أصوات )

الترجمة الالية للوصف

  • مرات التنزيل: 134
  • متطلبات التشغيل:
  • الحجم:
  • الترخيص:
  • الاصدار : 1.2
  • اضيف في: 2012-11-07 00:00:00
  • اخر تحديث: 11/07/2012
  • الموقع علي الانترنت:

استخدام البرامج التي تم تنزيلها من موقعنا يجب أن يكون وفقاً للقوانين في بلدك.لا نوصي باستخدام برامج تنتهك القوانين في بلدك.،اذا كنت تري ان هذا المحتوي لا يتوافق مع حقوق الملكية الفكرية برجاء ابلاغنا بالضغط هنا


Baker is a Python module that lets you easily add a command line interface to your Python functions using a simple decorator, to create scripts with "sub-commands", similar to Django's, svn, hg, etc.:#!pythonimport baker# An imaginary script full of useful Python [email protected] set(name, value=None, overwrite=False): """Sets the value of a key in the database. If you don't specify a value, the named key is deleted. Overwriting a value may not be visible to all clients until the next full sync. """ db = get_database() if overwrite or name not in db: if value is None: db.delete(name) print "Deleted %s" % name else: db.set(name, value) print "Set %s to %s" % (name, value) else: print "Key exists!"@baker.commanddef get(name): "Prints the value of a key in the database." db = get_database() print db.get(name) can then run the script and use your function names and parameters as the command line interface, using optparse-style options:$ set alfa bravoSet alfa to bravo$ set --overwrite alfa charlieSet alfa to charlie$ get alfacharlie$ --helpAvailable commands: get Prints the value of a key in the database. set Sets the value of a key in the databaseUse " < command > --help" for individual command help.$ set --helpUsage: set < name > [< value >]Sets the value of a key in the database. If you don't specify a value, the named key is deleted. Overwriting a value may not be visible to all clients until the next full sync.Options:--overwriteArgumentsBaker maps command line options to function parameters in the most natural way available.Bare arguments are used to fill in required parameters:@baker.commanddef test(a, b, c): print "a=", a, "b=", b, "c=", c$ test 1 2 3a= 1 b= 2 c= 3--option arguments are used to fill in keyword parameters. You can use --option value or --option=value, as in optparse:@baker.commanddef test(key="C"): print "In the key of:", key$ testIn the key of: C$ test --key AIn the key of: A$ test --key=GbIn the key of: GbFunction parameters where the default is None are considered optional arguments and will be filled if extra arguments are available. Otherwise, extra bare arguments never fill in keyword parameters:@baker.commanddef test(start, end=None, sortby="time"): print "start=", start, "end=", end, "sort=", sortby$ --sortby name 1start= 1 end= sortby= name$ 1 2start= 1 end= 2 sortby= timeIf a keyword parameter's default is an int or float, Baker will try to convert the option's string to the same type:@baker.commanddef test(limit=10): print type(limit)$ test --limit 10< type 'int' >If the default of a parameter is a boolean, the corresponding command line option is a flag that sets the opposite of the default:@baker.commanddef test(name, verbose=False): if verbose: print "Opening", name$ test --verbose alfaOpening alfaIf the function takes * and/or ** parameters, any leftover arguments and options will fill them in.Parameter helpBaker lets you specify help for parameters in three ways.In the decorator:@baker.command(params={"force": "Delete even if the file exists"})def delete(filename, force=False): "Deletes a file." if force or not os.path.exists(filename): os.remove(filename)In Python 3.x, you can use parameter annotations to associate doc strings with parameters:@baker.commanddef delete(filename, force:"Delete even if the file exists."=False): "Deletes a file." if force or not os.path.exists(filename): os.remove(filename)Baker can parse the function's docstring for Sphinx-style :param blocks:@baker.commanddef delete(filename, force=False): """Deletes a file. :param force: Delete even if the file exists. """ if force or not os.path.exists(filename): os.remove(filename)Short optionsTo allow single-character short options (e.g. -v for --verbose), use the shortopts keyword on the decorator:@baker.command(shortopts={"verbose": "v"}, params={"verbose", "Spew lots"})def test(verbose=False): pass$ test --helpUsage: testOptions: -v --verbose Spew lotsYou can group multiple short flag options together (-xvc). You can also optionally not put a space between a short option and its argument, for example -nCASE instead of -n CASE.MiscellaneousInstead of, you can use baker.test() to print out how Baker will call your function based on the given command line.As in many UNIX command line utilities, if you specify a single hyphen (-) as a bare argument, any subsequent arguments will not parsed as options, even if they start with --.Commands are automatically given the same name as the decorated function. To give a command a different name, use the name keyword on the decorator. This is especially useful when the command name you want isn't a valid Python identifier:@baker.command(name="track-all")def trackall(): passYou can specify a "default" command that is used when the first argument to the script doesn't look like a command name:@baker.command(default=True)def here(back=False): print "here! back=", [email protected] there(back=False): print "there! back=", back$ --backhere! back= TrueProduct's homepage Requirements:

· Python
What's New in This Release: [ read full changelog ]

· now prints the return value of the command function.
· Command usage help now shows help for optional arguments.
· Added options to
· Added baker.usage([commandname]).
· Added unit tests.
· Fixed bugs. only provide legal software, please help us keeping pur site legal, if you think this page is violating copyrights please let us know by clicking here Here

التعليقات علي Baker 1.2
اضافة تعليق

تعليقات الفيسبوك

تعليقات الموقع