Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

utilitários de linha de comando bonitos em python

547 Aufrufe

Veröffentlicht am

Palestra que vai procurar mostrar como escrever ferramentas de linha de comando, em um estilo correto e padronizado do Unix. Será um guia para mostrar o que se espera de um comando bem feito no Unix, e quais módulos do Python se pode usar para obter este efeito.

Veröffentlicht in: Bildung
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Antworten 
    Sind Sie sicher, dass Sie …  Ja  Nein
    Ihre Nachricht erscheint hier
  • Gehören Sie zu den Ersten, denen das gefällt!

utilitários de linha de comando bonitos em python

  1. 1. Utilitários de linha de comando bonitos em Python Rudá Moura TDC POA 2015
  2. 2. 2
  3. 3. 3
  4. 4. 4
  5. 5. Critério Interno • Projeto tem documentação clara e com exemplos • Projeto tem um conjunto de testes automatizados (unittests, nose, etc.) • Projeto tem uma boa estrutura de diretórios e arquivos • Projeto tem um buildsystem (make, setup.py, etc.) • Projeto instalável dentro de um Virtual Env 5
  6. 6. Critério Externo • Projeto possui uma licença de uso amigável (BSD, MIT, GPL, etc.) • Projeto está hospedado e possui uma homepage (GitHub, GitLab, Bitbucket, etc.) • Projeto possui documentação disponível on-line (readthedocs, github pages, etc.) • Projeto possui Integração Contínua (Jenkins, Travis, etc.) • Projeto disponível no Python Package Index [https://pypi.python.org/pypi] • Pacotes disponíveis no Debian, BSD Ports, Rudix, etc. • Projeto possui uma comunidade ativa e amigável 6
  7. 7. 7
  8. 8. Aspectos de Programação
  9. 9. Códigos de Retorno (Exit codes) • Muitos buildsystems (ex.: make) e sistemas de automação (ex.: fabric) necessitam do código de retorno para saber se podem continuar com a tarefa. • 0 = OK, !0 = NOK • 0 = programa rodou corretamente (EXIT_SUCCESS do C) • 1 = houve um erro na execução (EXIT_FAILURE do C) • 2.. = diferenciação de tipos de erros (não há um padrão) • 64-67 = EX_* (/usr/include/sysexits.h) • 128+n = saída com sinal n (143 = (128 + 15) SIGTERM) 9
  10. 10. Retorno em Python (seu script deve retornar um) • return 123 # dentro de __main__() • sys.exit(123) # em qualquer lugar • Caso contrário, assume um “retorna 0” OK (realmente, OK?) 10
  11. 11. Parsing de Argumentos • getopt (desde a antiguidade) • optparse (py2.3-py.2.7) • argparse (py2.7-) 11
  12. 12. 12
  13. 13. 13
  14. 14. 14
  15. 15. Logging • O módulo logging é odiado por não ser “Pythonico” porém o formato de logging e customizações são necessários em ambientes de produção • Em cada módulo: • log = logging.getLogger(__name__) • log.error(“Can’t start: %s”, msg) • log.info(), log.warn(), log.debug(), etc. 15
  16. 16. 16
  17. 17. Controle de Sinais (KeyboardInterrupt) • try / except KeyboardInterrupt:… • Módulo signal: • signal.signal(signal.SIGTERM, callback) • def callback(signum, stack)… 17
  18. 18. 18
  19. 19. Arquivos especiais • Módulos & Pacotes • snoopy/ • __init__.py • Executado quando faço ‘import snoopy’ • __main__.py • Executado quando faço ‘python -m snoopy’ 19
  20. 20. Ferramentas • Python Debugger (pdb) • import pdb ; pdb.set_trace() • profiler • virtualenv, tox (virtualenv-based automation of test activities) • pylint, pychecker • GitHub, Bitbucket, Travis, Jenkins, … • Um ótimo editor: vim, emacs, textmate, notepad++, etc. • Uma IDE: PyCharm, Eclipse, etc. 20
  21. 21. The Python Package Index (PyPI) • Central de repositórios de módulos para Python • Módulo distutils • Script setup.py • https://wiki.python.org/moin/Distutils/Tutorial 21
  22. 22. 22
  23. 23. 23
  24. 24. Documentação • Geralmente se escreve com Markdown ou reStructuredText (RST) • Markdown é mais simples de sintaxe e é um formato bem popular • RST é mais complexo, porém popular em projetos Python • Sphinx (Python Documentation Generator) [http:// sphinx-doc.org] 24
  25. 25. 25
  26. 26. 26
  27. 27. 27
  28. 28. Textbased User Interfaces (TUI) • ANSI Colors • colorconsole [https://pypi.python.org/pypi/colorconsole] • Interfaces Interativas (REPL) • Módulo cmd (o pdb faz uso dele) • Curses Interface • Clint, click, cliff [http://docs.python-guide.org/en/latest/ scenarios/cli/] 28
  29. 29. 29
  30. 30. 30
  31. 31. • Projeto tem uma licença amigável (BSD, MIT, GPL, etc.) • Projeto tem uma interface coerente e amigável • Projeto tem documentação clara e com exemplos • Projeto tem um conjunto de testes, cobertura e IC • Projeto disponível no PyPI • Projeto possui uma homepage • Projeto instalável dentro de um Virtual Env • Projeto tem uma comunidade legal • Projeto é mantido regularmente Resumo 31
  32. 32. Fim • Livro do Luciano Ramalho: “Fluent Python” • Rudix! Ports e packages para o OSX • rudix.org • HIRE ME! Me contrate :)

×