Skip to content

Instantly share code, notes, and snippets.

@ecylmz
Created June 5, 2011 14:15
Show Gist options
  • Save ecylmz/1008991 to your computer and use it in GitHub Desktop.
Save ecylmz/1008991 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#-*- coding: utf-8 -*-
import os
import sys
from datetime import date
# bu betik kendi sistemime özeldir.
SITE_PATH = "/home/ecylmz/github/ben/ecylmz.github.com"
os.chdir(SITE_PATH)
def write():
global full_file_name, title # send fonksiyonunun da ihtiyacı var.
# gerekli bilgileri alalım...
permalink = raw_input("Yazının linki ne olsun ? : ")
title = raw_input("Yazının başlığını girin : ")
category = raw_input("Yazı hangi kategori altına koyulsun ? [1-9] : ")
# alınan bilgileri işleyelim.
file_name = str(date.today()) + "-" + permalink + '.md'
full_file_name = SITE_PATH + '/' + category + '/_posts/' + file_name
# yazılacak dosya şablonunu oluşturalım...
content_header = "---\nlayout: post\ntitle: " + title + "\n---\n"
file = open(full_file_name, 'w')
file.write(content_header)
file.close()
# son gönderi kaydedelim belki! lazım olur.
history = open(".last_post", 'w')
history.write(full_file_name)
history.close()
# artık yazı yazılabilir.
os.system("$EDITOR " + full_file_name)
def edit(): # önceden kaydedilen geçmişi okuyalım...
os.chdir(SITE_PATH)
try:
file = open(".last_post", 'r')
last_post = file.read()
file.close()
os.system("$EDITOR " + last_post)
except:
print "Kayıtlı geçmiş yok. Önce bu betikle bir yazı oluştursan fena olmaz."
sys.exit()
def w_send(): # sıfırdan oluşturulan dosyalar için "write_send"
os.system('git add ' + full_file_name)
os.system('git commit -a -m' + '"' + title + ' eklendi."')
os.system('git push origin master')
def e_send(): # sadece düzenlenen dosyalar için "edit_send"
os.system('git commit -m "son gönderilen yazı düzenlendi."')
os.system('git push origin master')
def ask_send(send_type):
ask_send = raw_input("Dosya kaydedildi, github'a gönderilsin mi? [e/H] : ")
if ask_send in "eEyY":
send_type()
else :
print "Dosya github'a gönderilmedi.\nİşlem tamamlandı."
if __name__ == '__main__':
if len(sys.argv) != 2 or not("-e" in sys.argv or "-n" in sys.argv): # argüman sayısı 2 değilse ve -e ve -n dışında argüman verilmişse kullanımı gösterelim.
print "Kullanım:\n$ sayfa -e \t # Düzenlemek için\n$ sayfa -n\t # Yeni yazı için"
elif sys.argv[1] == '-e': # edit
edit()
ask_send(e_send)
elif sys.argv[1] == '-n': # new
write()
ask_send(w_send)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment