среда, 21 декабря 2016 г.
воскресенье, 11 декабря 2016 г.
CG Event 2016, Материалы к выступлению: GIT
part 2: GIT
пример работы с GIT на примере простых Nuke скриптов
git: video 1
git: video 2
так можно переопределить текстовый редактор Vim при commit
git config --global core.editor "'D:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
git config -l
чтобы достучаться через proxy
git config --global http.proxy http://[user]:[password]@[ip adress]:8080
git config --global --get http.proxy
добавить все файлы
git add .
исключить некоторые типы файлов из добавления в репозиторий
нужно создать файл .gitignore его содержание:
/.sources
/docs
*.bak
*~
*.db
*.pyc
файлы из указанных папок и указанных типов не будут добавляться в репозиторий
git config --global core.editor "'D:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
git config -l
чтобы достучаться через proxy
git config --global http.proxy http://[user]:[password]@[ip adress]:8080
git config --global --get http.proxy
добавить все файлы
git add .
исключить некоторые типы файлов из добавления в репозиторий
нужно создать файл .gitignore его содержание:
/.sources
/docs
*.bak
*~
*.db
*.pyc
файлы из указанных папок и указанных типов не будут добавляться в репозиторий
суббота, 10 декабря 2016 г.
четверг, 8 декабря 2016 г.
How can I create documentation with sphinx library
# генерация содержимого папки lib в папку docs/rst
sphinx-apidoc -o docs/rst .
sphinx-apidoc -o docs/rst .
# генерировать документацию
make html
для преодоления ошибок экранируем символы * обратной чертой \
"\*.py"
комментарии пишем с пропуском строки перед аргументами и внимательно относясь к отступам. Например:
text
arg:
comment
in the comment you can print :
for bold string:
in the comment you can print :
for bold string:
- **parameters**, **types**, **return** and **return types**::
for parametrs
parameters using :param <name>: <description>
type of the parameters :type <name>: <description>
returns using :returns: <description>
examples (doctest)
seealso using .. seealso:: text
notes using .. note:: text
warning using .. warning:: text
todo .. todo:: te
понедельник, 6 июня 2016 г.
пятница, 20 мая 2016 г.
How can you start IPython
for install enter string:
$ pip install "ipython[all]"
in the work catalog enter:
$ iptest notebook
$ pip install "ipython[all]"
in the work catalog enter:
$ iptest notebook
easy tutorial:
https://www.youtube.com/watch?v=H6dLGQw9yFQчетверг, 19 мая 2016 г.
How can I get the current time in python
-----------------------------------------
import time
time.asctime()
>>> 'Sat May 21 01:34:38 2016'
import time
gmtime = time.gmtime(time.time())
ftime = '%a %d %b %Y %H:%M:%S GMT'
str = time.strftime(ftime, gmtime)
str
>>> 'Fri 20 May 2016 22:35:40 GMT'
----------------------------------------
import email.utils
email.utils.formatdate()
>>> 'Fri, 20 May 2016 22:37:02 -0000'
email.utils.formatdate(localtime=True)
>>> 'Sat, 21 May 2016 01:36:46 +0300'
email.utils.formatdate(usegmt=True)
>>> 'Fri, 20 May 2016 22:36:57 GMT'
----------------------------------------
from datetime import datetime
print datetime.now()
>>> 2016-05-21 01:38:16.661000
print datetime.now().time()
>>> 01:38:27.261000
print datetime.utcnow()
>>> 2016-05-20 22:39:04.538000
now = datetime.now()
print '{}:{}:{}'.format(now.hour, now.minute, now.second)
>>> 1:40:12
import time
time.asctime()
>>> 'Sat May 21 01:34:38 2016'
import time
gmtime = time.gmtime(time.time())
ftime = '%a %d %b %Y %H:%M:%S GMT'
str = time.strftime(ftime, gmtime)
str
>>> 'Fri 20 May 2016 22:35:40 GMT'
----------------------------------------
import email.utils
email.utils.formatdate()
>>> 'Fri, 20 May 2016 22:37:02 -0000'
email.utils.formatdate(localtime=True)
>>> 'Sat, 21 May 2016 01:36:46 +0300'
email.utils.formatdate(usegmt=True)
>>> 'Fri, 20 May 2016 22:36:57 GMT'
----------------------------------------
from datetime import datetime
print datetime.now()
>>> 2016-05-21 01:38:16.661000
print datetime.now().time()
>>> 01:38:27.261000
print datetime.utcnow()
>>> 2016-05-20 22:39:04.538000
now = datetime.now()
print '{}:{}:{}'.format(now.hour, now.minute, now.second)
>>> 1:40:12
среда, 18 мая 2016 г.
How can I see or clear Nuke memory usage
nuke.clearRAMCache()
nuke.clearDiskCache()
def bytesto(bytes, to, bsize=1024):
"""convert bytes to megabytes, etc.
sample code:
print('mb= ' + str(bytesto(314575262000000, 'm')))
sample output:
mb= 300002347.946
"""
a = {'k': 1, 'm': 2, 'g': 3, 't': 4, 'p': 5, 'e': 6}
r = float(bytes)
# print 'r {}'.format(r)
for i in range(a[to]):
r = r / bsize
return (r)
print nuke.memory("info")
print nuke.memory("info", 'Read1')
print '{} Mb'.format(bytesto(nuke.memory("free"),'m'))
print '{} Mb'.format(bytesto(nuke.memory("usage"),'m'))
print '{} Mb'.format(bytesto(nuke.memory("total_ram"),'m'))
print '{} Gb'.format(bytesto(nuke.memory("total_vm"),'g'))
read about memory options:
print help(nuke.memory)
nuke.clearDiskCache()
def bytesto(bytes, to, bsize=1024):
"""convert bytes to megabytes, etc.
sample code:
print('mb= ' + str(bytesto(314575262000000, 'm')))
sample output:
mb= 300002347.946
"""
a = {'k': 1, 'm': 2, 'g': 3, 't': 4, 'p': 5, 'e': 6}
r = float(bytes)
# print 'r {}'.format(r)
for i in range(a[to]):
r = r / bsize
return (r)
print nuke.memory("info")
print nuke.memory("info", 'Read1')
print '{} Mb'.format(bytesto(nuke.memory("free"),'m'))
print '{} Mb'.format(bytesto(nuke.memory("usage"),'m'))
print '{} Mb'.format(bytesto(nuke.memory("total_ram"),'m'))
print '{} Gb'.format(bytesto(nuke.memory("total_vm"),'g'))
read about memory options:
print help(nuke.memory)
How do I read menu object in Nuke
inside the menu.py in Nuke, write global variable
n = nuke.menu('Nuke')
I can read the value of this object
print n.items().pop().items()[0].name()
print n.items().pop().items()[0].script()
print n.items().pop().items()[0].shortcut()
for menu_item in n.items():
print menu_item.name()
for menu_sub in menu_item.items():
try:
print '...{}'.format(menu_sub.name())
print '...{}'.format(menu_sub.script())
# print '...{}'.format(menu_sub.shortcut())
except:
pass
=========================
# Result: File
...New Comp...
...nuke.scriptNew("")
...Open Comp...
...nuke.scriptOpen("")
...Open Recent Comp
...Close Comp
...nuke.scriptClose()
...
...Save Comp
...nuke.scriptSave("")
...Save Comp As...
...nuke.scriptSaveAs("")
...Save New Comp Version
...nukescripts.script_and_write_nodes_version_up()
...
...Insert Comp Nodes...
...nukescripts.import_script()
...Export Comp Nodes...
...nukescripts.export_nodes_as_script()
...Comp Script Command...
...nukescripts.script_command('')
...Run Script...
...tcl_file()
...@;Next Frame
...frameBackward()
...@;Previous Frame
...frameForward()
...Comp Info
...nukescripts.script_data()
...
...Clear
...nuke.scriptClear()
...&Recent Files
Edit
...Undo
...nuke.undo()
...Redo
...nuke.redo()
...
...Cut
...nuke.nodeCopy(nukescripts.cut_paste_file()); nukescripts.node_delete(popupOnError=True)
...Copy
...nuke.nodeCopy(nukescripts.cut_paste_file())
and so on
n = nuke.menu('Nuke')
I can read the value of this object
print n.items().pop().items()[0].name()
print n.items().pop().items()[0].script()
print n.items().pop().items()[0].shortcut()
for menu_item in n.items():
print menu_item.name()
for menu_sub in menu_item.items():
try:
print '...{}'.format(menu_sub.name())
print '...{}'.format(menu_sub.script())
# print '...{}'.format(menu_sub.shortcut())
except:
pass
=========================
# Result: File
...New Comp...
...nuke.scriptNew("")
...Open Comp...
...nuke.scriptOpen("")
...Open Recent Comp
...Close Comp
...nuke.scriptClose()
...
...Save Comp
...nuke.scriptSave("")
...Save Comp As...
...nuke.scriptSaveAs("")
...Save New Comp Version
...nukescripts.script_and_write_nodes_version_up()
...
...Insert Comp Nodes...
...nukescripts.import_script()
...Export Comp Nodes...
...nukescripts.export_nodes_as_script()
...Comp Script Command...
...nukescripts.script_command('')
...Run Script...
...tcl_file()
...@;Next Frame
...frameBackward()
...@;Previous Frame
...frameForward()
...Comp Info
...nukescripts.script_data()
...
...Clear
...nuke.scriptClear()
...&Recent Files
Edit
...Undo
...nuke.undo()
...Redo
...nuke.redo()
...
...Cut
...nuke.nodeCopy(nukescripts.cut_paste_file()); nukescripts.node_delete(popupOnError=True)
...Copy
...nuke.nodeCopy(nukescripts.cut_paste_file())
and so on
How do I write try...except in one string
1. for nuke:
exec('try:\n n = nuke.toNode(\'DisableNodeController\'); k = n.knob(\'disable\'); k.setValue(0);\nexcept:\n nuke.message(\'DisableNodeController is not in scene\')')
2. second variant
def safecall(f, default=None, exception=Exception):
'''Returns modified f. When the modified f is called and throws an
exception, the default value is returned'''
def _safecall(*args,**argv):
try:
return f(*args,**argv)
except exception:
return default
return _safecall
[safecall(int)(i) for i in '1 2 x'.split()] # returns [1, 2, None]
[safecall(int, -1, ValueError)(i) for i in '1 2 x'.split()] # returns [1, 2, -1]
exec('try:\n n = nuke.toNode(\'DisableNodeController\'); k = n.knob(\'disable\'); k.setValue(0);\nexcept:\n nuke.message(\'DisableNodeController is not in scene\')')
2. second variant
def safecall(f, default=None, exception=Exception):
'''Returns modified f. When the modified f is called and throws an
exception, the default value is returned'''
def _safecall(*args,**argv):
try:
return f(*args,**argv)
except exception:
return default
return _safecall
[safecall(int)(i) for i in '1 2 x'.split()] # returns [1, 2, None]
[safecall(int, -1, ValueError)(i) for i in '1 2 x'.split()] # returns [1, 2, -1]
суббота, 7 мая 2016 г.
How print module attributes in the readable form
# easy function print list of the module attributes
# in the readable form
def print_module_attr(module, step_in=7):
attr_list = dir(module)
try:
num_line = int(ceil( len(attr_list)/step_in ))
for i in range(num_line):
print attr_list[i*step_in: (i+1)*step_in]
except ValueError as e:
print 'step_in must be not zero,\n error: {}'.format(e)
return
except TypeError as e:
print 'step_in must be int type,\n error: {}'.format(e)
return
def test_print_module_attr():
import os
print_module_attr(os, 8)
temp = 'test'; print temp
print_module_attr(temp, 8)
temp = 1; print temp
print_module_attr(temp, 8)
import os; print '0.003'
print_module_attr(os, 0.003)
print '1, 3'
print_module_attr(1, 3)
test_print_module_attr()
>>> ['F_OK', 'O_APPEND', 'O_BINARY', 'O_CREAT', 'O_EXCL', 'O_NOINHERIT', 'O_RANDOM', 'O_RDONLY']
['O_RDWR', 'O_SEQUENTIAL', 'O_SHORT_LIVED', 'O_TEMPORARY', 'O_TEXT', 'O_TRUNC', 'O_WRONLY', 'P_DETACH']
['P_NOWAIT', 'P_NOWAITO', 'P_OVERLAY', 'P_WAIT', 'R_OK', 'SEEK_CUR', 'SEEK_END', 'SEEK_SET']
['TMP_MAX', 'UserDict', 'W_OK', 'X_OK', '_Environ', '__all__', '__builtins__', '__doc__']
['__file__', '__name__', '__package__', '_copy_reg', '_execvpe', '_exists', '_exit', '_get_exports_list']
['_make_stat_result', '_make_statvfs_result', '_pickle_stat_result', '_pickle_statvfs_result', 'abort', 'access', 'altsep', 'chdir']
['chmod', 'close', 'closerange', 'curdir', 'defpath', 'devnull', 'dup', 'dup2']
['environ', 'errno', 'error', 'execl', 'execle', 'execlp', 'execlpe', 'execv']
['execve', 'execvp', 'execvpe', 'extsep', 'fdopen', 'fstat', 'fsync', 'getcwd']
['getcwdu', 'getenv', 'getpid', 'isatty', 'kill', 'linesep', 'listdir', 'lseek']
['lstat', 'makedirs', 'mkdir', 'name', 'open', 'pardir', 'path', 'pathsep']
['pipe', 'popen', 'popen2', 'popen3', 'popen4', 'putenv', 'read', 'remove']
['removedirs', 'rename', 'renames', 'rmdir', 'sep', 'spawnl', 'spawnle', 'spawnv']
['spawnve', 'startfile', 'stat', 'stat_float_times', 'stat_result', 'statvfs_result', 'strerror', 'sys']
['system', 'tempnam', 'times', 'tmpfile', 'tmpnam', 'umask', 'unlink', 'unsetenv']
['urandom', 'utime', 'waitpid', 'walk', 'write']
test
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__']
['__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__']
['__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__']
['__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split']
['_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs']
['find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace']
['istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace']
['rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines']
['startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
1
['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delattr__', '__div__']
['__divmod__', '__doc__', '__float__', '__floordiv__', '__format__', '__getattribute__', '__getnewargs__', '__hash__']
['__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', '__lshift__', '__mod__']
['__mul__', '__neg__', '__new__', '__nonzero__', '__oct__', '__or__', '__pos__', '__pow__']
['__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__']
['__rlshift__', '__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__']
['__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__']
['__trunc__', '__xor__', 'bit_length', 'conjugate', 'denominator', 'imag', 'numerator', 'real']
0.003
step_in must be int type,
error: range() integer step argument expected, got float.
1, 3
['__abs__', '__add__', '__and__']
['__class__', '__cmp__', '__coerce__']
['__delattr__', '__div__', '__divmod__']
['__doc__', '__float__', '__floordiv__']
['__format__', '__getattribute__', '__getnewargs__']
['__hash__', '__hex__', '__index__']
['__init__', '__int__', '__invert__']
['__long__', '__lshift__', '__mod__']
['__mul__', '__neg__', '__new__']
['__nonzero__', '__oct__', '__or__']
['__pos__', '__pow__', '__radd__']
['__rand__', '__rdiv__', '__rdivmod__']
['__reduce__', '__reduce_ex__', '__repr__']
['__rfloordiv__', '__rlshift__', '__rmod__']
['__rmul__', '__ror__', '__rpow__']
['__rrshift__', '__rshift__', '__rsub__']
['__rtruediv__', '__rxor__', '__setattr__']
['__sizeof__', '__str__', '__sub__']
['__subclasshook__', '__truediv__', '__trunc__']
['__xor__', 'bit_length', 'conjugate']
['denominator', 'imag', 'numerator']
['real']
среда, 4 мая 2016 г.
Kick Ass GUI
Very usefull GUI for Arnold Render:
http://www.genecrucean.com/applications/open-source/kick-ass-gui/
http://www.genecrucean.com/applications/open-source/kick-ass-gui/
bat file render in command line with kick.exe
@for %%i in (%*) do C:\solidangle\mtoadeploy\2013\bin\kick.exe -nstdin -l C:/solidangle/mtoadeploy/2013/shaders %%i -g 2.2 -dw -dp -nocrashpopup
pause
- drag-and-drop files on the bat file icon and begin rendering
Подписаться на:
Сообщения (Atom)