From 2423a6d942081b42e79d2dc258a0c941f0be3294 Mon Sep 17 00:00:00 2001 From: "Difrex(Denis Zheleztsov)" Date: Mon, 28 Apr 2014 12:04:17 +0400 Subject: [PATCH] check_config function --- Database.pm | 13 +++++++++---- Password.pm | 27 +++++++++++++++++++++++++-- pm.pl | 8 ++++++-- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/Database.pm b/Database.pm index 102d930..8af5380 100644 --- a/Database.pm +++ b/Database.pm @@ -1,15 +1,16 @@ package Database; use DBI; +use GPG; sub new { my $class = shift; # Get home dir - my $home = $ENV{HOME}; + my $home = $ENV->{HOME}; my $self = { - _home => $home; + _home => $home, }; bless $self, $class; @@ -27,7 +28,7 @@ sub connect { } sub mdo { - my ($self) = @_; + my ($self, $query, $type) = @_; my $dbh = $self->{_dbh}; } @@ -37,7 +38,7 @@ sub create_base { my $pm_dir = $home."/.PM/"; # Check dir - if !(-d $pm_dir) { + if (!(-d $pm_dir)) { # Create dirrectory @mkdir_cmd = ("mkdir", "$pm_dir"); system(@mkdir_cmd) == 0 or die "Cannot create dir $pm_dir: $!\n"; @@ -50,6 +51,10 @@ sub create_base { my $dbh = DBI->connect("dbi:SQLite:dbname=$pm_dir/db.sqlite","",""); print "Create database schema\n"; my $q_table = "create table passwords(name VARCHAR(32), resource TEXT, password TEXT)"; + $dbh->do($q_table); + + # Encrypt db + # TODO: write this return 0; } diff --git a/Password.pm b/Password.pm index cd575f7..01f561f 100644 --- a/Password.pm +++ b/Password.pm @@ -6,15 +6,38 @@ use utf8; use Database; +use PasswordSave; +use PasswordShow; + sub new { my $class = shift; + my $db = Database->new(); + + my $p_save = PasswordSave->new(); + my $p_show = PasswordShow->new(); + my $self = { - _home => $home, + _db => $db, + _p_save => $p_save, + _p_show => $p_show, }; bless $self, $class; return $self; } -1; +# Check configuration. If it doesn't exist create it. +sub check_config { + my ($self) = @_; + if (-e $ENV->{HOME}."/.PM/db.sqlite") { + return 0; + } + else { + my $db = $self->{_db}; + $db->create_base(); + } + return 0; +} + +1; \ No newline at end of file diff --git a/pm.pl b/pm.pl index 5702d78..38a634c 100755 --- a/pm.pl +++ b/pm.pl @@ -3,7 +3,7 @@ use Password; use Getopt::Std; -our $VERSION = '0.0.0a'; +our $VERSION = '0.0.0b'; # Debug use Data::Dumper; @@ -53,4 +53,8 @@ sub init() { } # Parse cmd line -init(); \ No newline at end of file +init(); + +my $pass = Password->new(); +# Don't use it's before GPG and Database +# $pass->check_config() == 0 or die "$!\n"; \ No newline at end of file